Closed stijnb1234 closed 1 month ago
Wow, I didn't expect that anyone besides from me is still using this messy und unfinished framework 😅
jda-commands only acknowledges events just before a reply or edit get's send. I can't remember for sure why I've implemented it this way, but I believe there was a reason to it.
When your function calls take longer than 3 seconds, the interaction expires resulting in an unknown interaction error.
There are two possible solutions:
@Button(value = "Random", emoji = "\uD83D\uDD27", ephemeral = true, style = ButtonStyle.PRIMARY)
public void onRandButton(ComponentEvent event) {
event.reply("Working on it...");
//time intense method call
event.reply("Second message, we are done!");
}
@Button(value = "Random", emoji = "\uD83D\uDD27", ephemeral = true, style = ButtonStyle.PRIMARY)
public void onRandButton(ComponentEvent event) {
((IMessageEditCallback) event.getContext().getEvent()).deferEdit().queue();
//time intense method call
event.reply("Second message, we are done!");
}
P.S.: Remember that all these method run on the main WS thread. I don't know what your function calls exactly do, but be sure to not block the event thread.
It's lovely and makes it a lot easier to work with 😛
I will check that out, thanks.
Works great, thanks again ;)
In a SlashCommand interaction, how can I later replace the first reply with the second one? @Kaktushose
I'm afraid that I dont understand your question. Can you give an example?
I'm afraid that I dont understand your question. Can you give an example?
Sure:
@SlashCommand(value = "roles", desc = "Get the roles", ephemeral = true)
public void onRoles(CommandEvent event) {
event.reply(Util.getEmbedBuilder()
.setTitle("Roles")
.setDescription("Working on it..."));
//TODO Do something...
//We are done with that, now replace the Working on it... message with a new one.
//Like this, it just sends a second reply on the first one. That's not what I want...
event.reply(Util.getEmbedBuilder()
.setTitle("Roles")
.setDescription("You have received the roles!"));
}
event.editReply(true)
should do the trick. This is normally set to true by default so I'm a little bit confused why this isn't working for you
Sadly it does not. It still replies to the first one.
Code used to test:
@Interaction
public class Test {
@SlashCommand("test")
public void onTest(CommandEvent e) {
e.editReply(true);
e.reply("Okay, we are working on it...");
// Wait 5 seconds
new java.util.Timer().schedule(new java.util.TimerTask() {
@Override
public void run() {
e.reply("Now we are done! This message should overwrite the first one.");
}
}, 5000);
}
}
Now it randomly seems to work again. Maybe it was just caused by my bad network connection on this location in combination with a timing issue?
No, I'm joking. It works in a different interaction (like button), but not in the first one (like the example above)?
I was able to reproduce the bug but didnt find the time yet to fix it
Hey @Kaktushose. Have you perhaps found time to look into this?
Sadly, no
Okay, I've looked into it:
Inside a CommandEvent you cannot use reply twice and expect the second call to edit the message. Edit reply only works for events that implement IMessageEditCallback
but SlashCommandInteractionEvent
only implements IReplyCallback
.
If you want to edit the message you need to use the success callback:
@SlashCommand("test")
public void onTest(CommandEvent event) {
event.reply("Original", message -> message.editMessage("Edit").queue());
}
Using the success callback had a bug, which was resolved with the latest commit on development
Cool, yeah that success callback wasn't an option because of that bug, but now it should work. Let me see, thanks. ;)
I have a slash command, which sends a reply with a button. When the user clicks on the button, I want to do some function calls (which takes some time) and then reply to the original interaction (replacing the original message).
However, when I do this, (sometimes) I get:
How can I do this correctly?
Example code: