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

624
Views
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 answers
Answer question

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 Report

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 Report

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 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!