admin管理员组

文章数量:1316523

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 mands. 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 mand = clientmands.find(cmd => cmd.name == args[0] || cmd.alias == args[0]);
        mand.run(message, args, client);
    } catch (error) {
        message.channel.send('Wrong mand.');
    }
});

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 (interactionmandName === 'join') {
        await interaction.reply('join');
    }

});

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 mands. 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 mand = client.mands.find(cmd => cmd.name == args[0] || cmd.alias == args[0]);
        mand.run(message, args, client);
    } catch (error) {
        message.channel.send('Wrong mand.');
    }
});

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.mandName === 'join') {
        await interaction.reply('join');
    }

});
Share Improve this question asked Oct 31, 2021 at 20:46 SuspenseSuspense 851 gold badge1 silver badge12 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

"An Interaction is the message that your application receives when a user uses an application mand or a message ponent." 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 mand perhaps?

Application mands are mands that an application can register to Discord, the built in slash mands 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

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.

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 mand at the moment but i use that for the button and any other ponent interaction, but slash mand 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

本文标签: javascriptDiscord JSinteractionCreate and messageCreateStack Overflow