Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button interactions randomly failing after some time #2756

Open
2 tasks done
Armynator opened this issue Oct 17, 2024 · 1 comment
Open
2 tasks done

Button interactions randomly failing after some time #2756

Armynator opened this issue Oct 17, 2024 · 1 comment
Labels
status: need more info in need of additional details

Comments

@Armynator
Copy link

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.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
Copy link
Contributor

freya022 commented Oct 17, 2024

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 version="1.0" encoding="UTF-8"?>
<configuration scan="true"> <!-- Reloads every minute -->
    <timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %boldCyan(%-26.-26thread) %boldYellow(%-20.-20logger{0}) %highlight(%-6level) %msg%n%throwable</pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>logs/latest.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>logs/logs-%d{yyyy-MM-dd}.log</fileNamePattern>

            <!-- keep 90 days worth of history capped at 3GB total size -->
            <maxHistory>90</maxHistory>
            <totalSizeCap>3GB</totalSizeCap>
        </rollingPolicy>

        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %-26.-26thread %-20.-20logger{0} %-6level %msg%n%throwable</pattern>
        </encoder>
    </appender>

    <!-- JDA -->
    <logger name="net.dv8tion.jda.internal.requests" level="trace" additivity="false">
        <appender-ref ref="FILE"/>
    </logger>

    <!-- All the remaining loggers -->
    <root level="info">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>

@MinnDevelopment MinnDevelopment added the status: need more info in need of additional details label Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: need more info in need of additional details
Projects
None yet
Development

No branches or pull requests

3 participants