use JDA delete message 10 seconds after sending

▼魔方 西西 提交于 2020-06-29 03:44:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!