Reputation: 85
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');
}
});
Upvotes: 2
Views: 17008
Reputation: 33
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.
Upvotes: 1
Reputation: 46
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 😃
Upvotes: 0
Reputation: 58
"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
Upvotes: 2