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

238
Visualizações
Have separate files per button & communicate with various command files when processing Discord's `interactionCreate` event for buttons?

Sorry if this seems vague, I've put as much effort into it as I can.

Discord.JS v13 has an event called interactionCreate. I am planning on migrating my Discord.JS v12 bot to v13 very soon, but I need to understand how to communicate my interactionCreate button events with my command files as well as have separate files for each button before I create my bot.

I don't have any code to show you because I haven't started making the v13 version of my bot, as I need to know this information before I start creating it.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Use the MessageComponent collectors to respond to interactions via a command file; no need to use interactionCreate for this.

about 4 years ago · Juan Pablo Isaza Relatório

0

There are many different ways you could achieve this but here is two ways to do it:

Functions for each command:

// index.js

client.on('interactionCreate', (interaction) => {
    if (interaction.isButton()) {
        switch (interaction.customId) {
            case 'command1':
                require('./commands/command1').handleButton(interaction);
                break;
            case 'command2':
                require('./commands/command2').handleButton(interaction);
                break;
            /* etc. */
        }
    }
    /* ... */
});
// commands/command1.js

/* command logic */

module.exports.handleButton = (interaction) => {
    /* logic here */
};

Collectors

You can find the documentation for message component collectors here

// index.js

client.on('interactionCreate', (interaction) => {
    if (interaction.isButton()) {
        return;
    }
    /* ... */
});
// commands/command1.js

/* ... */

const collector = message.createMessageComponentCollector({
    filter: (interaction) => {
        /* filter what message component you want to collect 
            for example: */
        return interaction.message.id === message.id;
    }
});

collector.on('collect', (interaction) => {
    /* button logic here */
});
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