discord-jda / JDA

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

Discord JDA loading SlashCommands #2637

Closed iFran2019 closed 5 months ago

iFran2019 commented 5 months ago

General Troubleshooting

Version of JDA

5.0.0-beta.21

Expected Behaviour

When the bot joins a server, it registers the slash commands, and if I kick it before they register on time, it throws an error. I wanted to see if I could handle this with a try-catch, but even if I put a catch (Exception e) {/code/}, it still happens. I'm not sure if it's a bug. Please help.

Code Example for Reproduction Steps

@Override
    public void onGuildJoin(GuildJoinEvent e){
        try {
            e.getGuild().upsertCommand(new CommandDataImpl("ping", "pong!")).wait();
        } catch (InterruptedException ex) {
            throw new RuntimeException(ex);
        }
    }

Code for JDABuilder or DefaultShardManagerBuilder used

private void JDABuild(String token) {
        TOKEN = token;
        jdaBuilder = JDABuilder.createDefault(TOKEN, Collections.emptyList());
        jdaBuilder.setStatus(onlineStatus);
        jdaBuilder.setActivity(Activity.playing(activityStatus));
        jda = jdaBuilder.build();
        try {
            jda.awaitReady();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

Exception or Error

15:19:03.507 ForkJoinPool.commonPool-worker-1              RestAction      ERROR  RestAction queue returned failure: [ErrorResponseException] 50001: Missing Access
net.dv8tion.jda.api.exceptions.ContextException: null
    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 net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:538)
    at i.fran2019.sigma.handlers.SlashCommandsHandler.loadGuildCommands(SlashCommandsHandler.java:130)
    at i.fran2019.sigma.handlers.SlashCommandsHandler.onGuildJoin(SlashCommandsHandler.java:142)
    at net.dv8tion.jda.api.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:447)
    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.handle(EventManagerProxy.java:70)
    at net.dv8tion.jda.internal.JDAImpl.handleEvent(JDAImpl.java:173)
    at net.dv8tion.jda.internal.handle.GuildSetupNode.completeSetup(GuildSetupNode.java:369)
    at net.dv8tion.jda.internal.handle.GuildSetupNode.handleMemberChunk(GuildSetupNode.java:260)
    at net.dv8tion.jda.internal.handle.GuildSetupNode.ensureMembers(GuildSetupNode.java:394)
    at net.dv8tion.jda.internal.handle.GuildSetupNode.handleCreate(GuildSetupNode.java:220)
    at net.dv8tion.jda.internal.handle.GuildSetupController.onCreate(GuildSetupController.java:170)
    at net.dv8tion.jda.internal.handle.GuildCreateHandler.handleInternally(GuildCreateHandler.java:44)
    at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:39)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:1007)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:893)
    at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:871)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:1046)
    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)
15:19:03.736 ForkJoinPool.commonPool-worker-1              RestAction      ERROR  RestAction queue returned failure: [ErrorResponseException] 50001: Missing Access
net.dv8tion.jda.api.exceptions.ContextException: null
    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 net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:538)
    at i.fran2019.sigma.handlers.SlashCommandsHandler.loadGuildCommands(SlashCommandsHandler.java:130)
    at i.fran2019.sigma.handlers.SlashCommandsHandler.onGuildJoin(SlashCommandsHandler.java:142)
    at net.dv8tion.jda.api.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:447)
    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.handle(EventManagerProxy.java:70)
    at net.dv8tion.jda.internal.JDAImpl.handleEvent(JDAImpl.java:173)
    at net.dv8tion.jda.internal.handle.GuildSetupNode.completeSetup(GuildSetupNode.java:369)
    at net.dv8tion.jda.internal.handle.GuildSetupNode.handleMemberChunk(GuildSetupNode.java:260)
    at net.dv8tion.jda.internal.handle.GuildSetupNode.ensureMembers(GuildSetupNode.java:394)
    at net.dv8tion.jda.internal.handle.GuildSetupNode.handleCreate(GuildSetupNode.java:220)
    at net.dv8tion.jda.internal.handle.GuildSetupController.onCreate(GuildSetupController.java:170)
    at net.dv8tion.jda.internal.handle.GuildCreateHandler.handleInternally(GuildCreateHandler.java:44)
    at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:39)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:1007)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:893)
    at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:871)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:1046)
    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)
MinnDevelopment commented 5 months ago

The wait() method has completely different meaning and I would recommend you to read the documentation for it, it is used for object monitors and not a JDA feature but a Java feature.

For error handling, have a look at ErrorHandler instead. The observed error response code here is ErrorResponse.MISSING_ACCESS.