Skip to content

Commit

Permalink
fix(event-handling): Cleanup page (#1526)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite authored Nov 28, 2023
1 parent 400d0db commit 8139ba3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
await interaction.reply('Pong!');
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('server')
.setDescription('Provides information about the server.'),
async execute(interaction) {
await interaction.reply(`This server is ${interaction.guild.name} and has ${interaction.guild.memberCount} members.`);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),
async execute(interaction) {
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`);
},
};
2 changes: 2 additions & 0 deletions code-samples/creating-your-bot/event-handling/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"clientId": "123456789012345678",
"guildId": "876543210987654321",
"token": "your-token-goes-here"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ module.exports = {
try {
await command.execute(interaction);
} catch (error) {
console.error(`Error executing ${interaction.commandName}`);
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
},
};
12 changes: 10 additions & 2 deletions guide/creating-your-bot/event-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ client.on(Events.InteractionCreate, async interaction => {
try {
await command.execute(interaction);
} catch (error) {
console.error(`Error executing ${interaction.commandName}`);
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
```
Expand Down Expand Up @@ -95,8 +99,12 @@ module.exports = {
try {
await command.execute(interaction);
} catch (error) {
console.error(`Error executing ${interaction.commandName}`);
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
},
};
Expand Down

0 comments on commit 8139ba3

Please sign in to comment.