Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

73
Visualizações
No message on buttonClick discord.js

When I click on button I get error "Interaction failed" This is full code I have written. What could be wrong here? I tried and interaction.create but no luck so far. Thank you.

Index.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);
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

First things first, there isn't an event called clickButton in discord.js unless you use extra npm packages such as discord.js-buttons. You can check the list of all the events at discord.js | Client. To execute a piece of code when a button is clicked, you would have to create a messageComponentCollector in the channel of your choice by doing:

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
});
about 4 years ago · Juan Pablo Isaza Relatório

0

For discord.js v13, clickButton is not an event. You need to use onInteraction then check if the interaction is a button.

For example:

client.on('interaction' (interaction) => {
  if (interaction.isButton()) {
    // do stuff
  }
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda