use JDA delete message 10 seconds after sending

后端 未结 1 1368
慢半拍i
慢半拍i 2021-01-28 05:07

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

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-28 06:01

    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
        System.out.println(result);
    }, (failure) -> { // failure is always a Throwable
        failure.printStackTrace();
    });
    

    I recommend reading the documentation and wiki:

    • RestAction javadocs
    • JDA wiki

    0 讨论(0)
提交回复
热议问题