Constantly getting "The application did not respond"

Hello, I am constantly getting the "The application did not respond" message. Not matter what I try to achieve the only thing that is fast enough to execute is a simple await interaction.reply('bla bla'). Anytime I try to do something from bulkDelete to sending embeds or creating buttons, I get the thing. Is there anything to try and debug that? Is it possible that my computer is too slow for developing a bot (lmao, it is not that slow though). Obviously defering doesn't do a thing. At first I thought my code was wrong but sometimes it works, sometimes it doesn't... One thing remains, this damn message telling me it didn't respond. Maybe there is a problem with how Sapphire handles my commands right now, found somewhere that a command handler could mess things up and take too long to load up the commands so in the meantime, no response... I really don't know what's happening, again if you have some kind of super debugging stuff or I don't know I'll take it
18 Replies
Seren_Modz 21
Seren_Modz 213d ago
defer the reply because you only get 3 seconds to respond to the interaction
d.js docs
d.js docs3d ago
:method: ChatInputCommandInteraction#deferReply() @14.16.3 Defers the reply to this interaction.
// Defer the reply to this interaction
interaction.deferReply()
.then(console.log)
.catch(console.error)
// Defer the reply to this interaction
interaction.deferReply()
.then(console.log)
.catch(console.error)
Seren_Modz 21
Seren_Modz 213d ago
after deferring the reply, you can then use editReply to update to your provided response
delios
deliosOP3d ago
Well yes
Obviously defering doesn't do a thing
Also (sorry for long text), this used to worked like twice or thrice and then never worked again
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
});
}
}
}
That's why I'm wondering if it isn't, not like a Sapphire problem, but how it handles things or did I mess up something at some point because clearly the code worked once then didn't work again
Seren_Modz 21
Seren_Modz 213d ago
if deferring isn't working, it's because your doing it too late. since your use ephemeral for your errors, move the defer to the very top so it runs as soon as possible
delios
deliosOP3d ago
I guess it still doesn't work (code)
async chatInputRun(interaction) {
try {
await interaction.deferReply({ ephemeral: true });

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

// Validate the number of messages to delete
if (messagesToDelete < 1 || messagesToDelete > 100) {
return interaction.editReply({
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.editReply({
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.editReply({
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.editReply({
content: 'Je n\'ai pas la permission de supprimer des messages dans ce salon.',
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 {
await interaction.deferReply({ ephemeral: true });

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

// Validate the number of messages to delete
if (messagesToDelete < 1 || messagesToDelete > 100) {
return interaction.editReply({
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.editReply({
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.editReply({
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.editReply({
content: 'Je n\'ai pas la permission de supprimer des messages dans ce salon.',
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
});
}
}
}
Putting it above the try also doesn't work
delios
deliosOP3d ago
Also the command is received instantly so it should do
No description
delios
deliosOP3d ago
I guess neither the bot nor my pc nor Sapphire is too slow just hm not working ig I guess adding ephemeral each time is redundant too but removing these doesn't change
Seren_Modz 21
Seren_Modz 213d ago
is your chatInputRun method being executed? perhaps you try adding a log at the top to check but also, showing the full file might help us more than just showing that method
delios
deliosOP3d ago
Pastebin
import { Command } from '@sapphire/framework';import { PermissionsB...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
delios
deliosOP3d ago
Here's the full file and let me see with log Hmm good point it's not being executed
Seren_Modz 21
Seren_Modz 213d ago
that would suggest that sapphire is not finding your command is your package.json main correctly setup?
delios
deliosOP3d ago
OK wait So I removed my precondition and my idHints which I guess would most likely be the cause Worked Re-added the exact same idHint Worked Re-added the exact same precondition Worked So I don't know am I just gambling it's working by removing random stuff? And restarting the bot with everything in place Doesn't work!!!!!!!!!!!!!!!!!!!!!!!! going mad!!!!!!!!!
Seren_Modz 21
Seren_Modz 213d ago
it could be that your AdminOnly precondition is not passing, thus not continuing to execute your command's code
Seren_Modz 21
Seren_Modz 213d ago
Sapphire Framework
Reporting precondition failure | Sapphire
When a precondition fails, it's usually important for the user to know why. For example, if they hit a cooldown or lack
delios
deliosOP3d ago
Will look into that Thank you very much for your patience and reading through long text for such a mistake And thank you for that piece of doc Have a very nice day Seren Btw don't want to be too cocky but does that seem correct lmao
import { Precondition } from '@sapphire/framework';

export class AdminOnlyPrecondition extends Precondition {
async messageRun(message) {
return this.checkAdmin(message.member);
}

async commandRun(message) {
return this.checkAdmin(message.member);
}

async interactionRun(interaction) {
return this.checkAdmin(interaction.member);
}

async checkAdmin(member) {
return member.permissions.has('ADMINISTRATOR')
? this.ok()
: this.error({ message: 'Vous n\'êtes pas un administrateur' });
}
}
import { Precondition } from '@sapphire/framework';

export class AdminOnlyPrecondition extends Precondition {
async messageRun(message) {
return this.checkAdmin(message.member);
}

async commandRun(message) {
return this.checkAdmin(message.member);
}

async interactionRun(interaction) {
return this.checkAdmin(interaction.member);
}

async checkAdmin(member) {
return member.permissions.has('ADMINISTRATOR')
? this.ok()
: this.error({ message: 'Vous n\'êtes pas un administrateur' });
}
}
Cuz' it's the culprit for all my suffering
Seren_Modz 21
Seren_Modz 213d ago
in discord.js v14, permissions aren't screaming snake case anymore so it would be Administrator instead of all caps
secre
secre3d ago
Or you can just use PermissionFlagsBits from discord.js const to get it. Way more reliable member?.permissions.has(PermissionFlagsBits.Administrator) like this
Want results from more Discord servers?
Add your server