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

626
Visualizações
Discord JS - interactionCreate and messageCreate

I've been trying to use interactionCreate event, but somehow it's not working. I'm not sure why, and I didn't find exact documentation about this event, only that it's used for executing slash commands. However for this purpose I use messageCreate event, and it's working fine.

const Event = require('../handlers/Event.js');

module.exports = new Event('messageCreate', (client, message) => {
    if (!message.content.startsWith(client.prefix) || message.author.bot) return;

    const args = message.content.substring(client.prefix.length).split(/ +/);
    try {
        const command = client.commands.find(cmd => cmd.name == args[0] || cmd.alias == args[0]);
        command.run(message, args, client);
    } catch (error) {
        message.channel.send('Wrong command.');
    }
});

What's wrong with my interactionCreate event?

const Event = require('../handlers/Event.js');

module.exports = new Event('interactionCreate', async (interaction) => {
    if (!interaction.isCommand()) return;

    if (interaction.commandName === 'join') {
        await interaction.reply('join');
    }

});
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

"An Interaction is the message that your application receives when a user uses an application command or a message component." Discord Interactions

The messageCreate listener will trigger for everything else pretty much.

In your case, what are you trying to do that will trigger the interaction? built in slash command perhaps?

Application commands are commands that an application can register to Discord, the built in slash commands I believe don't match this description. So for you to see an interaction firing you will either have to register an applicationCommand yourself (ApplicationCommandBuilder) or perhaps create an embed message with a button (DiscordButtons) and click the button which should trigger an interaction

about 4 years ago · Juan Pablo Isaza Relatório

0

Maybe you should wrap the entire code into one event . I believe that your event code was created twice , is not good for listening multiple event at the same time, to do that you should have to considering to declare one new event but iterate trough the event file. This what i use on my project last month in my index.js. Note that i wasnt use slash command at the moment but i use that for the button and any other component interaction, but slash command can be use that too.

const eventFiles = fs.readdirSync('./event').filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
    const event = require(`./event/${file}`);
    client.on(event.name, (...args) => event.execute(...args, any parameter here));
}

That could be the cleanest way to listen event at the same time. I hope this help 😃

about 4 years ago · Juan Pablo Isaza Relatório

0

I solved this problem just now. I have the same problem but maybe for a different reason. It's nothing about the code in my situation.

Before I use discord.js, I use the original API here. And I set the INTERACTIONS ENDPOINT URL as the tutorial described enter image description here

Then I started to use discord.js. But interactionCreate cannot work.

I re-set INTERACTIONS ENDPOINT URL to be nothing. Everything is OK now.

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