Bot crashes during second /command use

My clear-table command works perfectly the first time you use /clear-table, but the second time, it crashes when you click the Clear Table button. I am new to discordjs and this is my first time using components and collectors. https://gist.github.com/SowerofSystems/3f482470630ae1f90bcb526fecd6f3ff
Gist
console logs
console logs. GitHub Gist: instantly share code, notes, and snippets.
5 Replies
d.js toolkit
d.js toolkit6mo 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! - Marked as resolved by OP
d.js docs
d.js docs6mo ago
To share long code snippets, use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks or files. Common causes of DiscordAPIError[10062]: Unknown interaction: - Initial response took more than 3 seconds ➞ defer the response *. - Wrong interaction object inside a collector. - Two processes handling the same command (the first consumes the interaction, so it won't be valid for the other instance) * Note: you cannot defer modal or autocomplete value responses
SowerofSystems
SowerofSystems6mo ago
Sorry, I'm new to the server. I've added a Gist link as suggested by the bot I assume I must be misunderstanding something about editing deferred replies?
d.js docs
d.js docs6mo ago
If you are waiting for button or select menu input from a specific message, don't create the collector on the channel. - Channel collectors return component interactions for any component within that channel.
- <Channel>.createMessageComponentCollector(…)
+ <Message>.createMessageComponentCollector(…)
- <Channel>.createMessageComponentCollector(…)
+ <Message>.createMessageComponentCollector(…)
SowerofSystems
SowerofSystems6mo ago
Thank you. I changed the channel to message in confirmClear(), and while I still got errors when I used the command in quick succession, it was working more consistently. I got this error:
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
at Object.execute (D:\My Apps\VPS\blenda_bot\commands\dev\clear-table.js:46:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.execute (D:\My Apps\VPS\blenda_bot\events\interactionCreate.js:18:13)
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
at Object.execute (D:\My Apps\VPS\blenda_bot\commands\dev\clear-table.js:46:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.execute (D:\My Apps\VPS\blenda_bot\events\interactionCreate.js:18:13)
I stored my message in a const on creation and created the collector on that instead.
const message = await interaction.deferReply({ ephemeral: true });
const message = await interaction.deferReply({ ephemeral: true });
const collector = message.createMessageComponentCollector({
filter,
time: 15000
});
const collector = message.createMessageComponentCollector({
filter,
time: 15000
});
After making that change it's working perfectly now. I've also added a try/catch to handle any erroneous bugs so it doesn't crash the bot. I still don't entirely understand the issue, though. Is there any chance you could help me understand?