@@ -6,13 +6,13 @@ const commandTemplate = require('./resources/command_template.json');
6
6
const artList = require ( './resources/art.json' ) ;
7
7
8
8
console . log ( 'Starting bot, please give me a second.' ) ;
9
- client . on ( 'ready' , ( ) => {
10
-
11
- console . log ( 'I am ready to send some ASCII art!' ) ;
9
+ client . on ( 'ready' , async ( ) => {
12
10
13
11
client . user . setActivity ( 'you be awesome (☞゚ヮ゚)☞' , { type : "WATCHING" } ) ;
14
12
15
- CreateCommands ( ) ;
13
+ await CreateCommands ( ) ;
14
+
15
+ console . log ( 'I am ready to send some ASCII art!' ) ;
16
16
17
17
} ) ;
18
18
@@ -22,39 +22,47 @@ async function CreateCommands() {
22
22
23
23
let commandData = [ ] ;
24
24
25
+ // Loops through the art.json file, creating a new command based on the commandTeplate.json file for each one.
25
26
let i = 1 ;
26
27
artList . forEach ( artObject => {
27
28
28
29
console . log ( `${ i } . Creating a command for: \'${ artObject . name } \'.` ) ;
29
- let command = { ...commandTemplate } ;
30
+ let command = { ...commandTemplate } ; // Copying the command template into a new variable.
30
31
command . name = artObject . name ;
31
32
command . description = command . description . replace ( '[art]' , artObject . art ) ;
32
33
commandData . push ( command ) ;
33
34
i ++ ;
34
-
35
35
} ) ;
36
36
37
37
console . log ( `Deploying ${ commandData . length } commands.` ) ;
38
38
39
- await client . guilds . cache . get ( '434786513688199169' ) ?. commands . set ( commandData ) ;
39
+ // Deploying commands for all guilds (might take up to an hour to load everywhere).
40
+ await client . application ?. commands . set ( commandData ) ;
41
+
42
+ // Deploy the commands to a specific guild, for testing purposes - the global commands take up to an hour to load, the guild commands are instant.
43
+ //await client.guilds.cache.get('GUILD_ID')?.commands.set(commandData);
40
44
41
45
}
42
46
43
47
client . on ( 'interactionCreate' , async interaction => {
44
48
if ( ! interaction . isCommand ( ) ) return ;
45
49
50
+ // Find the art in art.json based on the command the user used.
46
51
const asciiArt = artList . find ( art => art . name === interaction . commandName ) ;
47
52
if ( ! isAsciiArtValid ( asciiArt ) ) return ;
48
53
54
+ // Get the message the user added, if any.
49
55
let message = interaction . options . getString ( 'message' ) ;
50
56
57
+ // If the user added a message, append the art to the end of said message. Otherwise just send the art.
51
58
const replyString = message === null ? asciiArt . art : message + ' ' + asciiArt . art ;
52
59
53
60
console . log ( `Sending \'${ asciiArt . name } \'.` ) ;
54
61
interaction . reply ( replyString ) ;
55
62
56
63
} ) ;
57
64
65
+ // Does the art from art.json have all the necessary info?
58
66
function isAsciiArtValid ( artObject ) {
59
67
60
68
const valid = ( artObject . art !== null && artObject . art . trim ( ) . length !== 0 ) &&
0 commit comments