He estado jugando con las opciones de Slash Commands que DiscordJS agregó en V13. Creé mis controladores de comandos y eventos, y todo arranca bien.
El comportamiento actual es:
1.) Arranca sin problema. Todos los mensajes de confirmación se cargan en la consola y los comandos se registran
2.) Cuando ejecuté el comando /ping por primera vez en el canal de Discord, recibí el siguiente mensaje Mensaje de error de Discord
3.) Cuando ejecuto el comando /ping por segunda vez, recibo una respuesta exitosa de "¡Pong!" en el canal ingresé el comando en
4.) Cuando ejecuto el comando /ping por tercera vez, recibo una respuesta exitosa de "¡Pong!" pero el bot falla con el siguiente mensaje de error
C:\Users\XXXX\Documents\bot\discordBot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:94 if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); ^ Error [INTERACTION_ALREADY_REPLIED]: The reply to this interaction has already been sent or deferred. at CommandInteraction.reply (C:\Users\XXXX\Documents\bot\discordBot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:94:46) at Client.<anonymous> (C:\Users\XXXX\Documents\bot\discordBot\events\interactionCreate.js:17:23) at processTicksAndRejections (node:internal/process/task_queues:96:5) { [Symbol(code)]: 'INTERACTION_ALREADY_REPLIED' }Me estoy quedando sin ideas sobre cómo resolver esto. Probé en el comando Ping varias opciones de respuesta a la interacción, pero ninguna solucionó el problema. ¿Alguien se ha encontrado con esto?
Tengo una muestra de código completo en mi Github para revisar: https://github.com/DBAggie/discordBot/tree/dev
Ok, después de algunas pruebas, encuentro dónde está el problema. Simplemente vuelve a escuchar el evento por cada interactionCreate se activa.
Así que primero no responderá. Y escuche un nuevo evento de creación de interactionCreate .
module.exports = { name: 'interactionCreate', execute(interaction, client) { client.on('interactionCreate', async interaction => { console.log(`hit the interaction create script`) if (!interaction.isCommand()) return console.log('Not a valid command'); const command = client.commands.get(interaction.commandName); if (!command) return; try { console.log('Trying to execute') await command.execute(interaction); } catch (error) { await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); } console.log('Below the catch'); }); //console.log('Below the below catch message'); } }; module.exports = { name: "interactionCreate", async execute(interaction, client) { console.log(`hit the interaction create script`); if (!interaction.isCommand()) return console.log("Not a valid command"); const command = client.commands.get(interaction.commandName); if (!command) return; try { console.log("Trying to execute"); await command.execute(interaction); } catch (error) { await interaction.reply({ content: "There was an error while executing this command!", ephemeral: true, }); } console.log("Below the catch"); //console.log('Below the below catch message'); }, };¿Mira aquí? Escuchas un nuevo evento cuando cada interacción.
execute(interaction, client) { client.on('interactionCreate', async interaction => {