discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.35k stars 734 forks source link

Button interactions randomly failing after some time #2756

Open Armynator opened 1 month ago

Armynator commented 1 month ago

General Troubleshooting

Version of JDA

5.1.2

Expected Behaviour

Sometimes button interactions randomly start failing and won't work anymore until a full bot restart. This happens seemingly randomly, sometimes after a few hours, sometimes after a few days of the bot running without a restart.

The interactions sometimes only fail in some channels. Sometimes they start failing in all.

Nothings happens, no event is fired, just the error is logged: java.lang.IllegalStateException: Failed to create channel instance for interaction! Channel Type: 0

I've pasted the full stack trace below, with some details such as the exact channel data removed. After restarting the bot, the same interactions suddenly all work again.

Code Example for Reproduction Steps

public class ButtonCommandsListener implements EventListener {
    @Override
    public void onEvent(GenericEvent event) {
        if (!(event instanceof final net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent buttonInteractionEvent)) {
            return;
        }
        buttonInteractionEvent.reply("Test").setEphemeral(true).queue();
    }
}

Code for JDABuilder or DefaultShardManagerBuilder used

jda = JDABuilder.createLight(token)
                .setAutoReconnect(true)
                .enableIntents(GatewayIntent.MESSAGE_CONTENT)
                .enableIntents(GatewayIntent.GUILD_MEMBERS)
                .addEventListeners(new ReadyListener())
                .addEventListeners(new UserUpdateNameListener())
                .addEventListeners(new UserMessageReceivedListener())
                .addEventListeners(new UserMessageDeletedListener())
                .addEventListeners(new UserRoleChangeListener())
                .addEventListeners(new UserJoinListener())
                .addEventListeners(new UserLeaveListener())
                .addEventListeners(new UserMessageEditedListener())
                .addEventListeners(new ServerEventRedirectListener())
                .addEventListeners(new ButtonCommandsListener())
                .addEventListeners(new SlashCommandListener())
                .build();
jda.awaitReady();

Exception or Error

19:08:01.957 [JDA MainWS-ReadThread] ERROR n.d.j.i.requests.WebSocketClient -- Got an unexpected error. Please redirect the following message to the devs:
        JDA 5.1.2_5f799f1
        INTERACTION_CREATE -> {"entitlements":[],... (REDACTED)
java.lang.IllegalStateException: Failed to create channel instance for interaction! Channel Type: 0
        at net.dv8tion.jda.internal.interactions.InteractionImpl.<init>(InteractionImpl.java:81)
        at net.dv8tion.jda.internal.interactions.DeferrableInteractionImpl.<init>(DeferrableInteractionImpl.java:33)
        at net.dv8tion.jda.internal.interactions.component.ComponentInteractionImpl.<init>(ComponentInteractionImpl.java:48)
        at net.dv8tion.jda.internal.interactions.component.ButtonInteractionImpl.<init>(ButtonInteractionImpl.java:33)
        at net.dv8tion.jda.internal.handle.InteractionCreateHandler.handleAction(InteractionCreateHandler.java:134)
        at net.dv8tion.jda.internal.handle.InteractionCreateHandler.handleInternally(InteractionCreateHandler.java:86)
        at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:39)
        at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:1009)
        at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:892)
        at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:870)
        at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:1048)
        at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:385)
        at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:276)
        at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:996)
        at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:755)
        at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:108)
        at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64)
        at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)
freya022 commented 1 month ago

I assume this is due to the interaction channel not being in the cache

If you have a way of checking after the error, try to inspect the channel cache, see which channels may be missing, also try another channel

Enable trace logs for the net.dv8tion.jda.internal.requests package, so you can see if there's a point in which the channel was deleted, the general goal being to reconstitute what happened exactly

Sample logback.xml This config below will save the package's logs to a file, other logs will remain in the console ```xml %d{HH:mm:ss.SSS} %boldCyan(%-26.-26thread) %boldYellow(%-20.-20logger{0}) %highlight(%-6level) %msg%n%throwable logs/latest.log logs/logs-%d{yyyy-MM-dd}.log 90 3GB %d{HH:mm:ss.SSS} %-26.-26thread %-20.-20logger{0} %-6level %msg%n%throwable ```