Buttons Interactions
Hello fellows, I have some questions.
I'm a developer with experience with jda-ktx and JDA, I'm not great with shappire, I'm trying to learn it because it is really fast to boot up and does all of the things in milliseconds compared to the java one.
My question is, I have many embeds with buttons, they should modify the embed for the user that created the embed, but I have no idea how cold I do that.
Does anyone know how I can fix this?
38 Replies
I'm not sure if I write it correctly I'm not native English speaker, If someone needs more information I can provide them
Pretty sure this is covered in the discordjs guide, assuming I understand you correctly. https://discordjs.guide/#before-you-begin
As for the sapphire layer that's https://sapphirejs.dev/docs/Guide/interaction-handlers/what-are-they
Editing the message when clicking a button is within the realm of basics of handling interactions anyway.
Sapphire Framework
What are they? | Sapphire
These are interaction handlers! A simple class you can extend to handle almost all the interactions you may receive in
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
if there are 3 embeds they are gonna get modified all of them
it is correct?
like in jdx-kotlin you don't use the id, you use the callbacks to modify the message/interact with it
I'm not sure if it's the same
Depends on the data you pass to the edit.
In essence yet because ultimately it's still the same discord API
well In JDA I had the problem about IDs
with the ktx version which implements callback I had no issues, because it doesn't modify other embeds, but the only one created by the user
seems like this uses ID where if the id is present somewhere else it's gonna modify that embed too
I got the point?, do you understand what I mean?
You can totally achieve this with discordjs as well. You just need to edit the right parts. It all comes down to the code you write.
I know, but how to?
What code do you have so far
It doesn't have callback buttons it's all based on some IDs which isn't unique per embed
It's a bit hard to be specific without specific questions
basics from the guide
I'm making a simple blackjack game to play with it, there is hit and stand as buttons
both of them modify the embed with the updated game status
How about you first get to the point of sending the message with the embed and button at all and add a console log when someone clicks the button and THEN worry about handling the action to take on the click
Do it one step at a time
I have everything already done
need only the buttons logic
Well that sounds like more than basics from the guide.
I'm not quite sure if they modify the other embeds
I cannot I'm not home, this is just brainstorm
When asking for help, make sure to provide as much detail as possible. What have you tried so far? Do you have stack traces that you can show us? What are you trying to achieve? Try to answer these questions and others, so we do not have to ask for them afterwards.
❯ For a good guide on how to ask questions, see the instructions that StackOverflow gives. You should try to always follow these guidelines. ❯ For an excellent video that shows how not to ask technical questions, watch this YouTube video by LiveOverflow. ❯ Asking technical questions (Clarkson) ❯ How to ask questions the smart way (Raymond)
Let's just revisit it when you are then please
I'm in the phase of the clicking the hit or the stand buttons which modify the embed
the question is, if I have multiple games running on in different embeds, if I click one button of them does it modify the other embeds?
No because every interaction is bound to a message and you call an update on that message
They're automatically bound.
well I need to use interactions
which needs an ID
which is the button id
If you'd want to edit another message then you'd have to fetch it and update it that way, those are extra steps you don't accidentally do
Nono, every embed is the same
just the game status changes
which changes the context of the embed
that's what I'm saying
They're not the "same" because they're tied to different messages
yes
Discordjs handles that for you automatically
Alright thanks, if I have any issues I can ask here for help?
Just don't worry about it and call editReply on the interaction
Yes
alright thanks I will let you know!
Uhm I need some help
this ain't working
I have no idea hwo to use it
I don't know what I'm doing because I need to use 2 classes
How can I get the callbacks instead of doing the class interaction?
Wdym callback? I have a feeling you mean something other than what a callback means in typescript. Granted I have never used the term for java either so maybe you don't.
Like maybe you can post some pseudo code of what you expect
at any rate I think you want to call editReply
for example https://github.com/favware/dragonite/blob/main/src/interaction-handlers/select-menus/itemSelectMenu.ts and https://github.com/sapphiredev/utilities/blob/4ec2cfe779f4fde2ddf33b3c6d5efd1aa24963c2/packages/discord.js-utilities/src/lib/PaginatedMessages/PaginatedMessage.ts#L1434and https://github.com/sapphiredev/utilities/blob/4ec2cfe779f4fde2ddf33b3c6d5efd1aa24963c2/packages/discord.js-utilities/src/lib/PaginatedMessages/utils.ts#L232
well
let me show you in koltin
jda.button(label = "Hit", style = ButtonStyle.SUCCESS, user = user) { buttonHit -> }
do something with buttonHitokay so i'm pretty sure that's called a lambda function in java
but anyway
pretty much what you wrote above plus the links that I shared should get you there. For example the PaginatedMessage ones have buttons
#149 - Dragonite
Type(s)
Dragon, Flying
Abilities
Inner Focus and Multiscale
Gender Ratio
50% | 50%
Evolutionary line
Dratini
→ Dragonair
(30) → Dragonite (55)Base Stats
HP: 91, ATK: 134, DEF: 95, SPA: 100, SPD: 100, SPE: 80 (BST: 600)
1 / 4
see how that has buttons. If I click them it updates the embed and goes to different pages. They're bound to me so only I can use them for this embed but if you use the same command you get buttons that are bound to you and only update the embed of your command, not the one I used
Hmm
Solution
seems like my embed chages status
mybad