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

290
Views
Discord JS: respuesta del bot a través del botón de mensaje

Actualmente estoy aprendiendo a usar los botones de Discords, pero me encontré con un problema. El siguiente código debe crear un botón con el comando /startgame, cuando presionas este botón, solo debe decir "hola".

 const { SlashCommandBuilder } = require("@discordjs/builders") const { MessageButton, MessageActionRow } = require("discord.js") module.exports ={ data: new SlashCommandBuilder() .setName("startgame") .setDescription("Startet das Spiel"), async execute(interactionCreate) { if (interactionCreate.isCommand()) { const row1 = new MessageActionRow() .addComponents( new MessageButton() .setCustomId("start") .setLabel(" Start ") .setStyle(3) .setDisabled(false), ) await interactionCreate.reply({content: " ", components: [row1]}) } else if(interactionCreate.isButton()) { switch (interactionCreate.customId) { case "start": { return interactionCreate.reply("hello") } } } } }

Crea el botón, pero al presionarlo solo dice: This interaction failed agradezco cualquier ayuda.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Bien, entonces una de estas partes debería estar bajo la interactionCreate del detector de eventos Crear en lugar de un comando. Entonces, si tiene esa sección en su archivo bot.js principal, se vería así:

Archivo de comandos

 const { SlashCommandBuilder } = require("@discordjs/builders") const { MessageButton, MessageActionRow } = require("discord.js") module.exports = { data: new SlashCommandBuilder() .setName("startgame") .setDescription("Startet das Spiel"), async execute(interaction) { const row1 = new MessageActionRow() .addComponents( new MessageButton() .setCustomId("start") .setLabel(" Start ") .setStyle(3) ) return interaction.reply({ components: [row1] }) } }

archivo bot.js: podría llamarse como lo hayas llamado

 client.on('interactionCreate', async interaction => { if (interaction.isButton()) { const buttonID = interaction.customId if (buttonID === 'start') { interaction.reply({ content: 'Hello' }) } } })
about 4 years ago · Juan Pablo Isaza 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!