diff --git a/code-samples/creating-your-bot/command-deployment/commands/moderation/kick.js b/code-samples/creating-your-bot/command-deployment/commands/moderation/kick.js deleted file mode 100644 index 241cea257..000000000 --- a/code-samples/creating-your-bot/command-deployment/commands/moderation/kick.js +++ /dev/null @@ -1,12 +0,0 @@ -const { SlashCommandBuilder } = require('discord.js'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('kick') - .setDescription('Select a member and kick them (but not really).') - .addUserOption(option => option.setName('target').setDescription('The member to kick').setRequired(true)), - async execute(interaction) { - const member = interaction.options.getMember('target'); - return interaction.reply({ content: `You wanted to kick: ${member.user.username}`, ephemeral: true }); - }, -}; diff --git a/code-samples/creating-your-bot/command-deployment/commands/moderation/prune.js b/code-samples/creating-your-bot/command-deployment/commands/moderation/prune.js deleted file mode 100644 index 46a57f69a..000000000 --- a/code-samples/creating-your-bot/command-deployment/commands/moderation/prune.js +++ /dev/null @@ -1,21 +0,0 @@ -const { SlashCommandBuilder } = require('discord.js'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('prune') - .setDescription('Prune up to 99 messages.') - .addIntegerOption(option => option.setName('amount').setDescription('Number of messages to prune')), - async execute(interaction) { - const amount = interaction.options.getInteger('amount'); - - if (amount < 1 || amount > 99) { - return interaction.reply({ content: 'You need to input a number between 1 and 99.', ephemeral: true }); - } - await interaction.channel.bulkDelete(amount, true).catch(error => { - console.error(error); - interaction.reply({ content: 'There was an error trying to prune messages in this channel!', ephemeral: true }); - }); - - return interaction.reply({ content: `Successfully pruned \`${amount}\` messages.`, ephemeral: true }); - }, -}; diff --git a/code-samples/creating-your-bot/command-deployment/commands/utility/avatar.js b/code-samples/creating-your-bot/command-deployment/commands/utility/avatar.js deleted file mode 100644 index b62e33b75..000000000 --- a/code-samples/creating-your-bot/command-deployment/commands/utility/avatar.js +++ /dev/null @@ -1,13 +0,0 @@ -const { SlashCommandBuilder } = require('discord.js'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('avatar') - .setDescription('Get the avatar URL of the selected user, or your own avatar.') - .addUserOption(option => option.setName('target').setDescription('The user\'s avatar to show')), - async execute(interaction) { - const user = interaction.options.getUser('target'); - if (user) return interaction.reply(`${user.username}'s avatar: ${user.displayAvatarURL()}`); - return interaction.reply(`Your avatar: ${interaction.user.displayAvatarURL()}`); - }, -}; diff --git a/code-samples/creating-your-bot/command-deployment/commands/fun/ping.js b/code-samples/creating-your-bot/command-deployment/commands/utility/ping.js similarity index 84% rename from code-samples/creating-your-bot/command-deployment/commands/fun/ping.js rename to code-samples/creating-your-bot/command-deployment/commands/utility/ping.js index 6352ea952..64e2ba6f9 100644 --- a/code-samples/creating-your-bot/command-deployment/commands/fun/ping.js +++ b/code-samples/creating-your-bot/command-deployment/commands/utility/ping.js @@ -5,6 +5,6 @@ module.exports = { .setName('ping') .setDescription('Replies with Pong!'), async execute(interaction) { - return interaction.reply('Pong!'); + await interaction.reply('Pong!'); }, }; diff --git a/code-samples/creating-your-bot/command-deployment/commands/utility/server.js b/code-samples/creating-your-bot/command-deployment/commands/utility/server.js index 959fcb4b6..277a28a4a 100644 --- a/code-samples/creating-your-bot/command-deployment/commands/utility/server.js +++ b/code-samples/creating-your-bot/command-deployment/commands/utility/server.js @@ -3,8 +3,8 @@ const { SlashCommandBuilder } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() .setName('server') - .setDescription('Display info about this server.'), + .setDescription('Provides information about the server.'), async execute(interaction) { - return interaction.reply(`Server name: ${interaction.guild.name}\nTotal members: ${interaction.guild.memberCount}`); + await interaction.reply(`This server is ${interaction.guild.name} and has ${interaction.guild.memberCount} members.`); }, }; diff --git a/code-samples/creating-your-bot/command-deployment/commands/utility/user.js b/code-samples/creating-your-bot/command-deployment/commands/utility/user.js index 6ef0ba88e..6007c727e 100644 --- a/code-samples/creating-your-bot/command-deployment/commands/utility/user.js +++ b/code-samples/creating-your-bot/command-deployment/commands/utility/user.js @@ -5,8 +5,6 @@ module.exports = { .setName('user') .setDescription('Provides information about the user.'), async execute(interaction) { - // interaction.user is the object representing the User who ran the command - // interaction.member is the GuildMember object, which represents the user in the specific guild await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`); }, }; diff --git a/code-samples/creating-your-bot/command-deployment/index.js b/code-samples/creating-your-bot/command-deployment/index.js index d0e170500..6f6968b58 100644 --- a/code-samples/creating-your-bot/command-deployment/index.js +++ b/code-samples/creating-your-bot/command-deployment/index.js @@ -29,10 +29,12 @@ client.once(Events.ClientReady, readyClient => { client.on(Events.InteractionCreate, async interaction => { if (!interaction.isChatInputCommand()) return; + const command = interaction.client.commands.get(interaction.commandName); - const command = client.commands.get(interaction.commandName); - - if (!command) return; + if (!command) { + console.error(`No command matching ${interaction.commandName} was found.`); + return; + } try { await command.execute(interaction); diff --git a/guide/creating-your-bot/command-deployment.md b/guide/creating-your-bot/command-deployment.md index 4a312f568..a1497269b 100644 --- a/guide/creating-your-bot/command-deployment.md +++ b/guide/creating-your-bot/command-deployment.md @@ -50,7 +50,7 @@ const fs = require('node:fs'); const path = require('node:path'); const commands = []; -// Grab all the command files from the commands directory you created earlier +// Grab all the command folders from the commands directory you created earlier const foldersPath = path.join(__dirname, 'commands'); const commandFolders = fs.readdirSync(foldersPath);