#Button collector
1 messages · Page 1 of 1 (latest)
well eventually i would want to specify buttons for doing specific functions
im making a pagination button
for an embed
ive tried using dependencies and such to do it for me but none of them work
Are you calling that client.on inside or outside of a function?
oh inside a function
If it's inside, I would move it outside on the same level as the client.login
im using a command handler so i get errors when i put it outside the function
let me try using any other event collector
You can use the client.on() just make sure it's outside of a function, and if you're going to do it in the function you'll want to use .awaitMessageComponent or .createMessageComponentCollector
i dont think i can use client.on outside of a function so i could use either of those two message components to collect a button interaction?
You can use client.on anywhere, but it's good to register it at the top level so that it doesn't just get called each time that function gets called. If you want it each time it gets called, it's better to use a .createMessageComponentCollector()
btw, im using slash commands. i hope that doesnt mess anything up
It doesn't
oh wait nvm i can use it
let me see if that was the problem
here is my code
the command handler works btw im using reconlx
i have several other commands that i use with it and it works fine
If you're trying to do it in a command function, I would just use a .createMessageComponentCollector()
yeah i think i'll try that
👍
works thanks for your time
oh cool i'll probably have to make one when my bot picks up
My bot is just for a group I'm in, but with all the features we need things like staff applications and verification management
makes sense, final question, since you cant go back pages once youre at the first page how would i use .setDisabled(true) on the back button for that message?
like this for example
but since it wont work until you interact with a button, should i incorporate it before hand as well?
You could either create the button and disable it from the start if it's the first page, or just don't even create it if it's the first page
true
i think i like disabling it
so the buttons dont shift around
so i would need to make two more buttons?
Also, be careful with what you have there, because it may just move other ones forward as well
wdym
Back & Next
I mean if you run the command twice, and click the second one, it's currently going to go through and edit each message since it's just listening for a button with customId forward
the else is for the other button
i only have two
if its not one, then it has to be the other
i thought
I mean if you execute the command twice
Like
Hey [back] [next]
Hey [back] [next]
And click next on the second one
They'll both change
😉
.setCustomId(JSON.stringify({ type: "forward", id: message.id }))
``` ```js
const data = JSON.parse(i.customId);
// data.type == "forward"
// data.id == 012345678912345678
hm so let me understand this, it only fires for the message of the button you clicked on
like if you hit next on the second one, it only updates for the second one?
im not familiar with anything there but if it works it works
oh what does the json file do
Well, I use it for every button, but more specifically one of the event_cancel buttons
the JSON stringify and parse just turn out object into a string, then back into an object
Basically allowing us to send over custom data along with it
So we can work with a specific element
if (interaction.isButton()) {
const interactionData = JSON.parse(interaction.customId)
const button = Client.buttons.get(interactionData.type);
if (!button) return;
try {
await button.execute(Client, interaction, interactionData.extraData);
} catch (e) {
console.error(`[ERROR] ${e}`);
await interaction.followUp({ content: `There was an error executing this button function!`, ephemeral: true });
}
}```
so just having that i can have that in the back and i can keep my code the same as i had
Yeah
You can leave your code and add that stuff in there
Then that way you can go and edit the message for the button if the message id is the same
I can make a quick demo if you want
oh ok how do you use ephemeral i swear theres something you need to add for it to work
ephemeral is just if it's only going to be shown to the user who interacted with it
i.e., clicked a button, ran a command
yeah ik but it doesnt work for me
Wdym?
It's most likely because you have editReply when no reply has been sent. So try interaction.reply()
the editReply was when it said bot is thinking....
because this is a message so i can edit it inplace of a command
Oh do you have it go and immediately do interaction.deferReply() in your command handler?
Or does the command handler do that
so, im not extremely familiar with the typescript and everything used for the handler but i assume youre talking about this deferReply
Yes
Then you can change it back to editReply
Not sure why it's saying unknown interaction..
Ah
But you would also need to have the ephemeral: true inside of the deferReply if you want it to only show to that user
would that be for all commands then?
or why dont i get rid of the deferReply in that file
and then i specify where needed
If you put it in there, yes it would be for all commands. that's why for the command handler I made, I just do the deferReply at the start of each command
oh lets go finally pops up as an option now
should work
yep it does work thank you, btw something annoying me, i have this slash command and i have no clue where its from, its not in my file
?
nvm
now the empheral works but not the content
where do i put the content of the message in?
.editReply({content:"", ephemeral: true});
and where does the deferReply go??
it seems the ephermal only works inside a deferReply
i just deleted the deferReply in my command handler that i showed you
So, you don't have to defer them, that's just if the reply can or will be more than 3 seconds late
So for the ones that need deferReply, just add it at the top of each run function you have.
And if you want it to only show to the caller, set ephemeral
this is what i have so far
then i get this
the error kind of makes sense but not really
Yeah, so you don't have a deferReply anymore, so now you don't need to editReply, unless you .reply() to it
So you can either defer at the top so it thinks, or just interaction.reply()
wtf..
i looked it up people said it had to do with the 3 second wait or something like that
...
whyy this is so dumb
oh alr thanks for the help
Np, hope you can get that last thing solved
