Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

625
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda