createMessageComponentCollector timeout answer

Yahallo 🕊️. I'm learning [email protected] and have encountered an unpleasant situation. The thing is that I am creating a collector on a temporary button:
const pageControl = await response.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 20000,
});
const pageControl = await response.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 20000,
});
It is valid for 20 seconds after which I disable it button.setDisabled(true). Everything works fine, the bot performs the action when clicked and disables the button after the time expires. I have no problems until I decide to restart the bot. After restarting, the bot simply does not manage to disable the button in time. So when I click the button after a restart, I get a Discord error that the bot is not responding. The button actions work directly from the command. In commands.js there is a handler pageControl.on('collect', async buttonInteraction => {} Main question: Is there any way to make the bot check somehow, if the user clicked on an expired button, the bot would give a message like “interaction is out of date, reuse the command”
3 Replies
d.js toolkit
d.js toolkit7mo 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
Amgelo
Amgelo7mo ago
you could try checking the Client's ready timestamp and the button's message creation timestamp if the client was ready after the message was created, then it was sent on a previous "session" to listen to any interaction (button, command, etc) just listen to interactionCreate, it's what collectors do in the background then just filter accordingly using the typeguards (Interaction#isButton(), Interaction#isModalSubmit(), etc) you could also include some kind of key in your button's customId, eg "AutoExpire-<actualCustomId>" and check if the button has that, to avoid filtering out other buttons by mistake
lolmak
lolmakOP7mo ago
That's a good one, thanks! I'll add if (interaction.isButton()) {} to the handler and put a check inside by timestamp.
Want results from more Discord servers?
Add your server