Skip to content

Commit 435d4e2

Browse files
author
Tadeas Salvatore Jun
committed
Code cleanup
1 parent 246d929 commit 435d4e2

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

bot.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const commandTemplate = require('./resources/command_template.json');
66
const artList = require('./resources/art.json');
77

88
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 () => {
1210

1311
client.user.setActivity('you be awesome (☞゚ヮ゚)☞', {type: "WATCHING"});
1412

15-
CreateCommands();
13+
await CreateCommands();
14+
15+
console.log('I am ready to send some ASCII art!');
1616

1717
});
1818

@@ -22,39 +22,47 @@ async function CreateCommands() {
2222

2323
let commandData = [];
2424

25+
// Loops through the art.json file, creating a new command based on the commandTeplate.json file for each one.
2526
let i = 1;
2627
artList.forEach(artObject => {
2728

2829
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.
3031
command.name = artObject.name;
3132
command.description = command.description.replace('[art]', artObject.art);
3233
commandData.push(command);
3334
i++;
34-
3535
});
3636

3737
console.log(`Deploying ${commandData.length} commands.`);
3838

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);
4044

4145
}
4246

4347
client.on('interactionCreate', async interaction => {
4448
if (!interaction.isCommand()) return;
4549

50+
// Find the art in art.json based on the command the user used.
4651
const asciiArt = artList.find(art => art.name === interaction.commandName);
4752
if(!isAsciiArtValid(asciiArt)) return;
4853

54+
// Get the message the user added, if any.
4955
let message = interaction.options.getString('message');
5056

57+
// If the user added a message, append the art to the end of said message. Otherwise just send the art.
5158
const replyString = message === null ? asciiArt.art : message + ' ' + asciiArt.art;
5259

5360
console.log(`Sending \'${asciiArt.name}\'.`);
5461
interaction.reply(replyString);
5562

5663
});
5764

65+
// Does the art from art.json have all the necessary info?
5866
function isAsciiArtValid(artObject) {
5967

6068
const valid = (artObject.art !== null && artObject.art.trim().length !== 0) &&

0 commit comments

Comments
 (0)