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?
Solution:
seems like my embed chages status
Jump to solution
38 Replies
✞
OP10mo ago
I'm not sure if I write it correctly I'm not native English speaker, If someone needs more information I can provide them
Favna
Favna10mo ago
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.
✞
OP10mo ago
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
Favna
Favna10mo ago
Depends on the data you pass to the edit. In essence yet because ultimately it's still the same discord API
✞
OP10mo ago
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?
Favna
Favna10mo ago
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.
✞
OP10mo ago
I know, but how to?
Favna
Favna10mo ago
What code do you have so far
✞
OP10mo ago
It doesn't have callback buttons it's all based on some IDs which isn't unique per embed
Favna
Favna10mo ago
It's a bit hard to be specific without specific questions
✞
OP10mo ago
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
Favna
Favna10mo ago
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
✞
OP10mo ago
I have everything already done need only the buttons logic
Favna
Favna10mo ago
Well that sounds like more than basics from the guide.
✞
OP10mo ago
I'm not quite sure if they modify the other embeds
✞
OP10mo ago
I cannot I'm not home, this is just brainstorm
Spinel
Spinel10mo ago
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)
Favna
Favna10mo ago
Let's just revisit it when you are then please
✞
OP10mo ago
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?
Favna
Favna10mo ago
No because every interaction is bound to a message and you call an update on that message They're automatically bound.
✞
OP10mo ago
well I need to use interactions which needs an ID which is the button id
Favna
Favna10mo ago
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
✞
OP10mo ago
Nono, every embed is the same just the game status changes which changes the context of the embed that's what I'm saying
Favna
Favna10mo ago
They're not the "same" because they're tied to different messages
✞
OP10mo ago
yes
Favna
Favna10mo ago
Discordjs handles that for you automatically
✞
OP10mo ago
Alright thanks, if I have any issues I can ask here for help?
Favna
Favna10mo ago
Just don't worry about it and call editReply on the interaction Yes
✞
OP10mo ago
alright thanks I will let you know! Uhm I need some help
const { InteractionHandler, InteractionHandlerTypes } = require('@sapphire/framework');
const BlackjackCommand = require('../commands/games/BlackjackCommand');

class BlackjackInteraction extends InteractionHandler {
constructor(ctx, options) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.Button,
});
this.game = BlackjackCommand.bj;
}

parse(interaction) {
if (interaction.customId !== 'hit' && interaction.customId !== 'stand') return this.none();

return this.some();
}

async run(interaction) {
if (interaction.customId === 'hit') {
this.game.hit();
await interaction.reply('You hit!');
}
else if (interaction.customId === 'stand') {
this.game.stand();
await interaction.reply('You stand!');
}
}
}

module.exports = {
BlackjackInteraction,
};
const { InteractionHandler, InteractionHandlerTypes } = require('@sapphire/framework');
const BlackjackCommand = require('../commands/games/BlackjackCommand');

class BlackjackInteraction extends InteractionHandler {
constructor(ctx, options) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.Button,
});
this.game = BlackjackCommand.bj;
}

parse(interaction) {
if (interaction.customId !== 'hit' && interaction.customId !== 'stand') return this.none();

return this.some();
}

async run(interaction) {
if (interaction.customId === 'hit') {
this.game.hit();
await interaction.reply('You hit!');
}
else if (interaction.customId === 'stand') {
this.game.stand();
await interaction.reply('You stand!');
}
}
}

module.exports = {
BlackjackInteraction,
};
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?
Favna
Favna10mo ago
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
✞
OP10mo ago
well let me show you in koltin jda.button(label = "Hit", style = ButtonStyle.SUCCESS, user = user) { buttonHit -> } do something with buttonHit
Favna
Favna10mo ago
okay 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
Dragonite
Dragonite10mo ago
#149 - Dragonite
Type(s)
Dragon, Flying
Abilities
Inner Focus and Multiscale
Gender Ratio
50% 2642 | 50% 2640
Evolutionary line
DratiniDragonair (30) → Dragonite (55)
Base Stats
HP: 91, ATK: 134, DEF: 95, SPA: 100, SPD: 100, SPE: 80 (BST: 600)
1 / 4
Favna
Favna10mo ago
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
✞
OP10mo ago
Hmm
Solution
✞
10mo ago
seems like my embed chages status
✞
OP10mo ago
mybad
Want results from more Discord servers?
Add your server