duplicated interactions
okay i need help, because i have been hititng my head against the wall abt this for days. my interactions keep doubling as per my console logs. for background info:
name: Events.InteractionCreate,
async execute(interaction) {
console.log(
if (interaction.isChatInputCommand()) {
await handleChatCommand(interaction);
} else if (interaction.isButton()) {
await handleButtonInteraction(interaction);
} else if (interaction.isAutocomplete()) {
await handleAutocomplete(interaction);
}
}
};
async function handleChatCommand(interaction) {
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(
return;
}
await command.execute(interaction, pool);
console.log(
}
async function handleButtonInteraction(interaction) {
if (interaction.customId === 'nextPage') {
//handle buttons. too long and not related to issue
}
}
async function handleAutocomplete(interaction) {
const command = interaction.client.commands.get(interaction.commandName);
await command.autocomplete(interaction).catch(err => {
console.log(err);
});
if (!interaction.deferred && !interaction.replied && interaction.isChatInputCommand()) {
interaction.reply({
content:
ephemeral: true
}).catch(console.error);
}
} //added to try to mitigate issue. did not make a difference
```
- there is only one instance being run
- i use an event handler -> separate files for events. other events do not double
- the interactionCreate event is only listened to once
- this applies to every interaction, including buttons (where i noticed this issue)
interactionCreate.js:
```const { Events, EmbedBuilder } = require('discord.js');
const pool = require('../bot')
const config = require('../config.json')
name: Events.InteractionCreate,
async execute(interaction) {
console.log(
interaction type: ${interaction.type});if (interaction.isChatInputCommand()) {
await handleChatCommand(interaction);
} else if (interaction.isButton()) {
await handleButtonInteraction(interaction);
} else if (interaction.isAutocomplete()) {
await handleAutocomplete(interaction);
}
}
};
async function handleChatCommand(interaction) {
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(
No command matching ${interaction.commandName} was found.);return;
}
await command.execute(interaction, pool);
console.log(
${interaction.user.username} used a command | ${interaction.commandName});}
async function handleButtonInteraction(interaction) {
if (interaction.customId === 'nextPage') {
//handle buttons. too long and not related to issue
}
}
async function handleAutocomplete(interaction) {
const command = interaction.client.commands.get(interaction.commandName);
await command.autocomplete(interaction).catch(err => {
console.log(err);
});
if (!interaction.deferred && !interaction.replied && interaction.isChatInputCommand()) {
interaction.reply({
content:
uh oh, an error occurred.,ephemeral: true
}).catch(console.error);
}
} //added to try to mitigate issue. did not make a difference
```
