Cuando hago clic en el botón, aparece el error "Interacción fallida". Este es el código completo que he escrito. ¿Qué podría estar mal aquí? Intenté e interact.create pero hasta ahora no tuve suerte. Gracias.
Índice.js
const { token } = require('./config.json'); const { Client, Intents } = require('discord.js'); const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); const { MessageActionRow, MessageButton, MessageEmbed } = require('discord.js'); const {gabriel} = require('./commands/gabriel.js') client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }); client.on('messageCreate', message => { if(message.content === "$gabriel") { gabriel(message); } }); client.on('clickButton', async (button) => { if(button.id === "11"){ await button.reply.defer() await button.message.channel.send("Skills are posted in here!") } else if (button.id === "12"){ await button.reply.defer() await button.message.channel.send("Constellation Data!") } }); client.login(token);Lo primero es lo primero, no hay un evento llamado clickButton en discord.js a menos que use paquetes npm adicionales como discord.js-buttons . Puedes consultar la lista de todos los eventos en discord.js | cliente Para ejecutar un fragmento de código cuando se hace clic en un botón, debe crear un messageComponentCollector en el canal de su elección haciendo lo siguiente:
var filter = (click) => click.user.id === message.author.id; // Creating a filter to only allow some users to click the button const collector = message.channel.createMessageComponentCollector({ time: 1000 * 10 /* Choosing how long the collector can work. (The time is in milliseconds) */, max: 1 /* Defining the maximum number of clicks on the button */, filter: filter /* Applying the filter */, }); collector.on('collect', (click) => { // Execute some code });Para discord.js v13, clickButton no es un evento. Debe usar onInteraction y luego verificar si la interacción es un botón.
Por ejemplo:
client.on('interaction' (interaction) => { if (interaction.isButton()) { // do stuff } });