Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.2K
Views
Discord.js-button: DiscordAPIError: la interacción ya ha sido reconocida

Actualmente estoy codificando un bot discord. Tengo un error con los botones. La pregunta ya se hizo en el foro, pero no he encontrado una respuesta relevante... Al ejecutar el primer comando, todo funciona bien, al ejecutar el segundo comando, aparece este mensaje...

==> Aquí está el código:

 const Discord = require('discord.js'); const { MessageActionRow, MessageButton, MessageEmbed } = require('discord.js'); module.exports.run = async (client, message, args) => { const row = new MessageActionRow() .addComponents( new MessageButton() .setCustomId('yes') .setLabel('YES') .setStyle('SUCCESS'), new MessageButton() .setCustomId('no') .setLabel('NO') .setStyle('DANGER'), ); const embed = new MessageEmbed() .setColor('#0099ff') .setTitle('Some title') await message.reply({ embeds: [embed], components: [row] }); client.on('interactionCreate', async interaction => { if (interaction.customId == 'yes') { await interaction.reply({ content: 'You click on YES !', ephemeral: true }); }; }); }; module.exports.info = { names: ['t4', 'test4'], };

==> Aquí está el error:

 throw new DiscordAPIError(data, res.status, request); ^ DiscordAPIError: Interaction has already been acknowledged. at RequestHandler.execute (C:\Users\famou\OneDrive\Bureau\RPG Bot\node_modules\discord.js\src\rest\RequestHandler.js:298:13) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async RequestHandler.push (C:\Users\famou\OneDrive\Bureau\RPG Bot\node_modules\discord.js\src\rest\RequestHandler.js:50:14) at async ButtonInteraction.reply (C:\Users\famou\OneDrive\Bureau\RPG Bot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:99:5) at async Client.<anonymous> (C:\Users\famou\OneDrive\Bureau\RPG Bot\commands\test4.js:45:13) { method: 'post', path: '/interactions/997619679268970577/aW50ZXJhY3Rpb246OTk3NjE5Njc5MjY4OTcwNTc3OjJsZmhuWlJWaVJYNnJlcnhJNkFtSXhhcEllM2Vhd0VQdVJOYTQwdzF0Y3IyakpGWVh1Vkd1a3BXeHZyc25aTFFOYk9uMVQ2QkNFTGJPQmFaVjdvWG90eTB3V1I3ckR3ZFd3TGd3YjdGejREajBZeGhKUWtRc3F3c3BMdlR2QW1a/callback', code: 40060, httpStatus: 400, requestData: { json: { type: 4, data: { content: 'Ready! You closed the channel!', tts: false, nonce: undefined, embeds: undefined, components: undefined, username: undefined, avatar_url: undefined, allowed_mentions: undefined, flags: 64, message_reference: undefined, attachments: undefined, sticker_ids: undefined } }, files: [] } }

gracias ^^

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Está creando oyentes anidados. Está creando un oyente cada vez que se ejecuta el comando, sin realizar ninguna validación en la devolución de llamada, lo que hace que tome cada interacción, incluso desde un comando diferente. Una mejor opción es usar colectores .

 const msg = await message.reply({ embeds: [embed], components: [row] }); const collector = msg.createMessageComponentCollector({ componentType: "BUTTON", time: 15_000 // how long you want it to collect for, in ms (this is 15 seconds) }) collector.on('collect', async interaction => { if (interaction.customId == 'yes') { await interaction.reply({ content: 'You click on YES !', ephemeral: true }); }; });

Documentos: Message#createMessageComponentCollector()

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!