discord-jda/JDA

Message delete error

rafixtv opened this issue · 2 comments

General Troubleshooting

  • I have checked for similar issues on the Issue-tracker.
  • I have checked for PRs that might already address this issue.

Version of JDA

5.0.0 beta 18

Expected Behaviour

I cannot delete a message sent by a bot (it wasnt sent via webhook)
I have this error since the update with webhooks was introduced.

Code Example for Reproduction Steps

@Override
    public void onButtonInteraction(ButtonInteractionEvent e) {
        //doesnt work:
        e.getMessage().delete().queue();

        //works well:
        e.getChannel().deleteMessageById(e.getMessage().getIdLong()).queue();
    }

Code for JDABuilder or DefaultShardManagerBuilder used

JDABuilder jda = JDABuilder.createDefault(token)
                .addEventListeners(new InteractionsListener(),
                        new InviteListener(),
                        new VoiceChannelListener(),
                        new MessagesListener(),
                        new AntiNukeListener(),
                        new AntiSpamListener()
                )
                .setEventPassthrough(true)
                .setMemberCachePolicy(MemberCachePolicy.ALL)
                .setChunkingFilter(ChunkingFilter.NONE)
                .enableCache(CacheFlag.ACTIVITY)
                .setRateLimitPool(Scheduler.getExecutor())
                .setGatewayPool(Scheduler.getExecutor())
                .setAudioPool(Scheduler.getExecutor())
                .setCallbackPool(Scheduler.getExecutor())
                .setEventPool(Scheduler.getExecutor())
                .enableIntents(GatewayIntent.GUILD_PRESENCES, GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGES, GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_VOICE_STATES)
                .enableCache(CacheFlag.ONLINE_STATUS);

Exception or Error

[ERROR] (19:41:25) RestAction queue returned failure: [ErrorResponseException] 10015: Unknown Webhook
net.dv8tion.jda.api.exceptions.ContextException
at net.dv8tion.jda.api.exceptions.ContextException.here(ContextException.java:54)
at net.dv8tion.jda.api.requests.Request.<init>(Request.java:77)
at net.dv8tion.jda.internal.requests.RestActionImpl.queue(RestActionImpl.java:197)
at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:572)
at xyz.rafix.randkobot.listeners.InteractionsListener.onButtonInteraction(InteractionsListener.java:255)
at net.dv8tion.jda.api.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:446)
at net.dv8tion.jda.api.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:96)
at net.dv8tion.jda.internal.hooks.EventManagerProxy.handleInternally(EventManagerProxy.java:88)
at net.dv8tion.jda.internal.hooks.EventManagerProxy.lambda$handle$0(EventManagerProxy.java:68)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)

You should first use event.deferEdit().queue() to acknowledge you received the interaction. The delete request is a followup to that. Doing it the old way is discouraged, as it requires different permissions that you might not have.

Closing, since this is intended. As described above, interactions should always be acknowledged first.