"The application did not respond" on bulkDelete message use

Hello, just built my first slash command, what I coded seems fair though the command doesn't seem to be registered. When writing down / I don't even see my bot appearing (only the built-in stuff). Does the code seem fair? I can't see any major mistake that would make it not register...
import { Command } from '@sapphire/framework';

export class ClearCommand extends Command {
constructor(context, options) {
super(context, {
...options,
name: 'clear',
description: 'Supprime les derniers messages du salon actuel',
aliases: ['purge'],
preconditions: ['AdminOnly'],
idHints: ['1306666895696593017']
});
}

registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
.addIntegerOption((option) =>
option
.setName('nombre')
.setDescription('Nombre de message à supprimer')
.setRequired(true)
)
);
}

chatInputRun(interaction) {
const channel = interaction.channel;

const messagesToDelete = interaction.options.getInteger('nombre');

if (messagesToDelete > 100) {
return interaction.reply({
content: 'Vous ne pouvez pas supprimer plus de 100 messages à la fois',
ephemeral: true,
});
}

return channel.bulkDelete(messagesToDelete)
.then(() => {
interaction.reply({
content: `Messages supprimés avec succès`,
ephemeral: true,
});
})
}
}
import { Command } from '@sapphire/framework';

export class ClearCommand extends Command {
constructor(context, options) {
super(context, {
...options,
name: 'clear',
description: 'Supprime les derniers messages du salon actuel',
aliases: ['purge'],
preconditions: ['AdminOnly'],
idHints: ['1306666895696593017']
});
}

registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
.addIntegerOption((option) =>
option
.setName('nombre')
.setDescription('Nombre de message à supprimer')
.setRequired(true)
)
);
}

chatInputRun(interaction) {
const channel = interaction.channel;

const messagesToDelete = interaction.options.getInteger('nombre');

if (messagesToDelete > 100) {
return interaction.reply({
content: 'Vous ne pouvez pas supprimer plus de 100 messages à la fois',
ephemeral: true,
});
}

return channel.bulkDelete(messagesToDelete)
.then(() => {
interaction.reply({
content: `Messages supprimés avec succès`,
ephemeral: true,
});
})
}
}
Also I get this in the console if that means something
[DEBUG] ApplicationCommandRegistry[clear] Preparing to process 1 possible command registrations / updates...
[DEBUG] ApplicationCommandRegistry[clear] Checking if command "clear" is identical with global chat input command with id "1306666895696593017"
[DEBUG] ApplicationCommandRegistry[clear] Registering id "1306666895696593017" to internal chat input map
[DEBUG] ApplicationCommandRegistry[clear] Took 1ms to process differences via fast compute differences
[DEBUG] ApplicationCommandRegistry[clear] Found differences for command "clear" (1306666895696593017) versus provided api data.
[DEBUG] ApplicationCommandRegistry[clear] Updated command clear (1306666895696593017) with new api data
[INFO] ApplicationCommandRegistries: Took 251ms to initialize.
[DEBUG] ApplicationCommandRegistry[clear] Preparing to process 1 possible command registrations / updates...
[DEBUG] ApplicationCommandRegistry[clear] Checking if command "clear" is identical with global chat input command with id "1306666895696593017"
[DEBUG] ApplicationCommandRegistry[clear] Registering id "1306666895696593017" to internal chat input map
[DEBUG] ApplicationCommandRegistry[clear] Took 1ms to process differences via fast compute differences
[DEBUG] ApplicationCommandRegistry[clear] Found differences for command "clear" (1306666895696593017) versus provided api data.
[DEBUG] ApplicationCommandRegistry[clear] Updated command clear (1306666895696593017) with new api data
[INFO] ApplicationCommandRegistries: Took 251ms to initialize.
Solution:
More readable code : ```js async chatInputRun(interaction) { try {...
Jump to solution
29 Replies
delios
deliosOP2mo ago
Tried kicking - reinviting the bot which displays the command but then it says "application did not respond" and obviously kicking the bot each time I make or update a command isn't the way lol Also added ApplicationCommandRegistries.setDefaultBehaviorWhenNotIdentical(RegisterBehavior.BulkOverwrite); but that doesn't seem to change anything Also is that how you "idHint" a command?
constructor(context, options) {
super(context, {
...options,
name: 'clear',
description: 'Supprime les derniers messages du salon actuel',
aliases: ['purge'],
preconditions: ['AdminOnly'],
idHints: ['1306679675573112984']
});
}
constructor(context, options) {
super(context, {
...options,
name: 'clear',
description: 'Supprime les derniers messages du salon actuel',
aliases: ['purge'],
preconditions: ['AdminOnly'],
idHints: ['1306679675573112984']
});
}
Couldn't find more precision in the doc except telling you to do it
Favna
Favna2mo ago
it's not
Lioness100
Lioness1002mo ago
Global commands usually take a bit to update (up to an hour, usually under 10 minutes in my experience, and quicker if you restart your Discord client often). When you kicked and re-invited it, it probably refreshed its commands for your Discord client. But at that point the bot might've been offline or you had a different error in your code so it wasn't responsive
Favna
Favna2mo ago
Sapphire Framework
Registering Chat Input Commands | Sapphire
To register a Chat Input Command (also known as a Slash Command) with Discord, you need to acquire an application
Favna
Favna2mo ago
nah it's instant. It took that long only in slash v1 which is gone for a long time now. but there can be client side caching yes
Lioness100
Lioness1002mo ago
Oh oops That's good
delios
deliosOP2mo ago
Well well
Favna
Favna2mo ago
also aliases do nothing for slash commands btw. Since you provide the name and it only responds to that name
delios
deliosOP2mo ago
OK I'm on the wrong path for idHints first, got there which I thought was good lmao
No description
Favna
Favna2mo ago
that is also wrong
delios
deliosOP2mo ago
Well yes now I know
Favna
Favna2mo ago
import { Command } from '@sapphire/framework';

export class SlashCommand extends Command {
constructor(context, options) {
super(context, {
...options,
description: 'Say hello to a user.'
});
}

registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) =>
builder //
.setName(this.name)
.setDescription(this.description)
.addUserOption((option) =>
option //
.setName('user')
.setDescription('User to say hello to')
.setRequired(true)
),
{ idHints: ['....' }
);
}

chatInputRun(interaction) {
// ...
}
}
import { Command } from '@sapphire/framework';

export class SlashCommand extends Command {
constructor(context, options) {
super(context, {
...options,
description: 'Say hello to a user.'
});
}

registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) =>
builder //
.setName(this.name)
.setDescription(this.description)
.addUserOption((option) =>
option //
.setName('user')
.setDescription('User to say hello to')
.setRequired(true)
),
{ idHints: ['....' }
);
}

chatInputRun(interaction) {
// ...
}
}
delios
deliosOP2mo ago
Thank you for that :)
Favna
Favna2mo ago
Just saying but if you would switch from JavaScript to TypeScript the compiler would tell you about such mistakes, something to consider perhaps
delios
deliosOP2mo ago
Also true will look into that Hmm now I've got idHints thing correct Do I need to like clear my command to start fresh and actually put the idHints before it was generated 20 times?
Favna
Favna2mo ago
shouldnt need to but if you want to see what is currently registered you can use https://slash-commands-gui.androz2091.fr
Slash Commands GUI
Graphical User Interface to explore and edit your bot's slash commands!
delios
deliosOP2mo ago
No description
delios
deliosOP2mo ago
OK that's nice because now there's nothing
Favna
Favna2mo ago
as for the application not responding, at a glance the code looks fine although I would make chatInputRun async, await then bulkDelete then reply. I would also add a defer at the top since a bulk delete can take a while and you must respond within 5 seconds otherwise Discord considers the application failed to respond
delios
deliosOP2mo ago
I mean I did nothing and application still not responding from Discord so that makes sense but I really don't know what to aim for now
delios
deliosOP2mo ago
defer? you mean? Also that looks like that now if that is what you meant. And also I'm trying to delete just 1 message for testing purpose so I don't know if it should take that long or if that doesn't matter but yeah
No description
delios
deliosOP2mo ago
Lots of efforts for a 5 lines command ahah, thanks for your help btw hopefully next commands will be easier to setup
delios
deliosOP2mo ago
Well kind of made some research and got there but still The application did not respond. I think it's me not having the logic to make something long cool for Discord's API so if anyone has the recipe I'll take it
No description
delios
deliosOP2mo ago
Made a cool hello.mjs that does work in the meantime lol
No description
delios
deliosOP2mo ago
Well still not
No description
delios
deliosOP2mo ago
I am now filled with despair from a simple missed use of the integrated bulkDelete method :depressed: @Helpers if that makes sense....
delios
deliosOP2mo ago
This worked (o1 generated) I'm just stunned right now because it's smart and at the same time why can I not just call bulkDelete? Anyway I guess that'll do... Thanks y'all. By the way if anyone can spot what makes the difference I'll take it
No description
Solution
delios
delios2mo ago
More readable code :
async chatInputRun(interaction) {
try {
const messagesToDelete = interaction.options.getInteger('nombre');

// Validate the number of messages to delete
if (messagesToDelete < 1 || messagesToDelete > 100) {
return interaction.reply({
content: 'Veuillez spécifier un nombre entre 1 et 100.',
ephemeral: true
});
}

// Check if the interaction is in a guild
if (!interaction.guild) {
return interaction.reply({
content: 'Cette commande ne peut être utilisée que dans un serveur.',
ephemeral: true
});
}

// Ensure the channel is a text-based channel
const channel = interaction.channel;
if (!channel || !channel.isTextBased()) {
return interaction.reply({
content: 'Cette commande ne peut être utilisée que dans un salon texte.',
ephemeral: true
});
}

// Check if the bot has the required permissions
const botMember = interaction.guild.members.me;
if (!botMember.permissionsIn(channel).has(PermissionsBitField.Flags.ManageMessages)) {
return interaction.reply({
content: 'Je n\'ai pas la permission de supprimer des messages dans ce salon.',
ephemeral: true
});
}

await interaction.deferReply({ ephemeral: true });

// Fetch messages and filter out messages older than 14 days
const fetchedMessages = await channel.messages.fetch({ limit: messagesToDelete });
const messagesToBulkDelete = fetchedMessages.filter(
(msg) => Date.now() - msg.createdTimestamp < 14 * 24 * 60 * 60 * 1000
);

if (messagesToBulkDelete.size === 0) {
return interaction.editReply({
content: 'Aucun message récent à supprimer.',
});
}

// Bulk delete messages
const deletedMessages = await channel.bulkDelete(messagesToBulkDelete, true);

await interaction.editReply({
content: `${deletedMessages.size} messages ont été supprimés.`,
});
} catch (error) {
this.container.logger.error('Error in PurgeCommand:', error);

if (interaction.deferred || interaction.replied) {
await interaction.editReply({
content: 'Une erreur s\'est produite lors de la suppression des messages.',
});
} else {
await interaction.reply({
content: 'Une erreur s\'est produite lors de la suppression des messages.',
ephemeral: true
});
}
}
}
async chatInputRun(interaction) {
try {
const messagesToDelete = interaction.options.getInteger('nombre');

// Validate the number of messages to delete
if (messagesToDelete < 1 || messagesToDelete > 100) {
return interaction.reply({
content: 'Veuillez spécifier un nombre entre 1 et 100.',
ephemeral: true
});
}

// Check if the interaction is in a guild
if (!interaction.guild) {
return interaction.reply({
content: 'Cette commande ne peut être utilisée que dans un serveur.',
ephemeral: true
});
}

// Ensure the channel is a text-based channel
const channel = interaction.channel;
if (!channel || !channel.isTextBased()) {
return interaction.reply({
content: 'Cette commande ne peut être utilisée que dans un salon texte.',
ephemeral: true
});
}

// Check if the bot has the required permissions
const botMember = interaction.guild.members.me;
if (!botMember.permissionsIn(channel).has(PermissionsBitField.Flags.ManageMessages)) {
return interaction.reply({
content: 'Je n\'ai pas la permission de supprimer des messages dans ce salon.',
ephemeral: true
});
}

await interaction.deferReply({ ephemeral: true });

// Fetch messages and filter out messages older than 14 days
const fetchedMessages = await channel.messages.fetch({ limit: messagesToDelete });
const messagesToBulkDelete = fetchedMessages.filter(
(msg) => Date.now() - msg.createdTimestamp < 14 * 24 * 60 * 60 * 1000
);

if (messagesToBulkDelete.size === 0) {
return interaction.editReply({
content: 'Aucun message récent à supprimer.',
});
}

// Bulk delete messages
const deletedMessages = await channel.bulkDelete(messagesToBulkDelete, true);

await interaction.editReply({
content: `${deletedMessages.size} messages ont été supprimés.`,
});
} catch (error) {
this.container.logger.error('Error in PurgeCommand:', error);

if (interaction.deferred || interaction.replied) {
await interaction.editReply({
content: 'Une erreur s\'est produite lors de la suppression des messages.',
});
} else {
await interaction.reply({
content: 'Une erreur s\'est produite lors de la suppression des messages.',
ephemeral: true
});
}
}
}
delios
deliosOP2mo ago
Never fucking mind I had to pass "true" as bulkDelete second parameter, and I'm talking alone too much hope you had fun, I'm out!
Want results from more Discord servers?
Add your server