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: - 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')

module.exports = {
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
const { Events, EmbedBuilder } = require('discord.js');
const pool = require('../bot')
const config = require('../config.json')

module.exports = {
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
No description
6 Replies
d.js toolkit
d.js toolkit4mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
jamie
jamie4mo ago
posted here instead as i feel its a longer issue
xx_lavaboy_xx123
how do u know there's only 1 listener for interactionCreate? have u logged <Client>.listenerCount("interactionCreate")?
jamie
jamie4mo ago
yeah, it returns 0 - i know that means unlimited, but this wasn't an issue until after i started working on this new branch. one command defers a reply, but i don't think that would cause this setting maxListeners to 1 also does not fix the issue
xx_lavaboy_xx123
i don't think 0 means unlimited, i think it means u don't have any interactionCreate event listeners added to ur client so you probably logged it before adding the listeners, u should log it wherever u log the interaction type
jamie
jamie4mo ago
ah, gotcha. my bad, i assumed it was similar to maxListeners where 0 = unlimited returns 1 listener for interactionCreate it also emits the console log twice though :EGGsweat: :PLUMPblink: i think i fixed it actually...? it seems it was something in my shardingmanager file (main.js)