问题
I am making a discord bot that sends an embed to display a users inventory(im making a game bot). To avoid clutter I want to delete the message after 10-20 seconds. Anyone know how I can do this(If you completely understand the questions then pls dont say, "oh you need to follow blah blah format"). I am using Java eclipse with JDA.
Yes, I've looked it up and I couldn't find anything for JDA.
回答1:
You can use queueAfter
which will delay the execution of the RestAction
provided by delete()
.
public static void deleteAfter(Message message, int delay) {
message.delete().queueAfter(delay, TimeUnit.SECONDS);
}
This method can be used inside the success callback for your sendMessage
action.
someMethod().queue((result) -> { // the type for "result" is the T in RestAction<T>
System.out.println(result);
}, (failure) -> { // failure is always a Throwable
failure.printStackTrace();
});
I recommend reading the documentation and wiki:
- RestAction javadocs
- JDA wiki
来源:https://stackoverflow.com/questions/57564998/use-jda-delete-message-10-seconds-after-sending