How to get never timeout buttons
I want my buttons in messages to get interactions forever. Even when I re-run the code, it must still give interaction response. My code now ( it follows discordjs guide ) -
https://pastebin.com/h3kKzszT
I thought of removing the time, but it didn't work as I expected it to be. Please provide a detailed explanation about how I can achieve this.
Pastebin
Code - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
10 Replies
- 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 OPButtons never expire, what matters is if you are responding to its event in
interactionCreate
event listener, what you have there in the snippet is a collector, which is basically an event listener that temporarily listens to 'interactionCreate' event (in your case), and disposes itself when it's condition is met or if time expires, so it is not permanent, you should listen to the buttons interaction in your main interaction handler file if you want to handle the buttons all timesI have no idea how do I handle buttons. Please elaborate. Here's my part of code that handles slash command interactions.
Right, so what you do here is return if the interaction is not from slash commands, you need to slightly modify this, so instead of returning, wrap it all inside the if block using curly braces (
{}
) and then add another statement for buttons handling like
Now the handling button would be the same as how you are doing in your original code inside the collector, just check by it's ID and do what you want to do!
If you had advanced further in the guide, you would have known this.
https://discordjs.guide/message-components/interactions.html#the-client-interactioncreate-event this part explains how to handle different types of interactions, i suggest you give this a readYep. That works. But I have one more thing to ask. This method is good but everything looks cluttered now. Can I use the same
in my command files too? like for buttons in a file, I will make a new client.on in that file only.
No you should not create duplicate listeners everytime you want to, you should only have one unique listener ideally, what you can do is create a button handler similar to how you have command handler
Or separate things in files, make it a function and call that function inside your event listener and pass interaction to it
You shouldn't. That'll create a new event listener every time the command is ran. In general, you should only have 1 event listener per event. Instead, you can create a function to handle the button interaction, which could make it less cluttered.
I ain't getting what are you saying. I am kinda new to discordjs.
I added this line to the file where interactions are handled, inside the
client.on
.
And added this inside my command file -
I can't figure out by what The Gobbler said. Which line should I put in which file.
Sorry to mention but still waiting for an answer. @NyRUmm, no! They didn't tell you to add it to your command file, you can make another file and put this function there, export it and then import it in you interaction handler file and call it like you're doing
This is like basic js
Yes. I got what you said now. Thanks for help.
yes