midorina
midorina
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
What's the best practice to handle errors?
hmmm....
10 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
What's the best practice to handle errors?
.setDescription("An error occurred while executing the command:
.setDescription("An error occurred while executing the command:
" + error + "
")
")
10 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
What's the best practice to handle errors?
I can simply forward the message in the error promise, no?
10 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
What's the best practice to handle errors?
I can put more details into the message yes. currently my main concern is what the best way to handle errors is. I don't want to copy and paste the method above for each method that can fail, or wrap the whole function with a try-catch block
10 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
What's the best practice to handle errors?
then in this case idk how I exit the method above if an error has occurred unless I use a try-catch block :Thinkfusing:
10 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
What's the best practice to handle errors?
main method call:
const deleted = await interaction.channel.bulkDelete(messages, true)
.catch((err) => errorHandler(interaction, err));
const deleted = await interaction.channel.bulkDelete(messages, true)
.catch((err) => errorHandler(interaction, err));
the error handler method:
export async function errorHandler(
interaction: CommandInteraction,
error: Promise<Collection<string, Message<boolean> | PartialMessage | undefined>>
): Promise<boolean> {
console.error("[ERROR]", error);
if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
embeds: [
new EmbedBuilder()
.setColor("#FF0000")
.setTitle("❌ Error")
.setDescription("An error occurred while executing the command.")
],
flags: MessageFlags.Ephemeral
});

return true;
}

return false;
}
export async function errorHandler(
interaction: CommandInteraction,
error: Promise<Collection<string, Message<boolean> | PartialMessage | undefined>>
): Promise<boolean> {
console.error("[ERROR]", error);
if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
embeds: [
new EmbedBuilder()
.setColor("#FF0000")
.setTitle("❌ Error")
.setDescription("An error occurred while executing the command.")
],
flags: MessageFlags.Ephemeral
});

return true;
}

return false;
}
would this be considered the good practice?
10 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
Any way to check if the bot has sufficient perms to execute a command with SlashCommandBuilder()?
I see. thanks
25 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
Any way to check if the bot has sufficient perms to execute a command with SlashCommandBuilder()?
it does not have to be in the slash command data that we send to Discord. it's a check that the lib can do when the command is executed, no?
25 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
Any way to check if the bot has sufficient perms to execute a command with SlashCommandBuilder()?
it's in interaction.guild.members.me.permissions
25 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
Any way to check if the bot has sufficient perms to execute a command with SlashCommandBuilder()?
what do you mean?
25 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
Any way to check if the bot has sufficient perms to execute a command with SlashCommandBuilder()?
im curious why such a simple method does not exist on the builder
25 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
Any way to check if the bot has sufficient perms to execute a command with SlashCommandBuilder()?
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages) // this exists. this checks user's perms
.setBotPermission(PermissionFlagsBits.ManageMessages); // this is what I need
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages) // this exists. this checks user's perms
.setBotPermission(PermissionFlagsBits.ManageMessages); // this is what I need
25 replies
DIAdiscord.js - Imagine an app
Created by midorina on 3/24/2025 in #djs-questions
Any way to check if the bot has sufficient perms to execute a command with SlashCommandBuilder()?
but I can pass the flags, no?
25 replies