B4J Question [JDA] Bot is starting, but no events are called

shadowdevfr

Member
Hi. I'm trying to make a bot in b4j using @DonManfred 's JDA library.
While my bot does start and appears online in discord, it's not calling any events related to it.
Here are the logs:
B4X:
Waiting for debugger to connect...
Program started.
juin 16, 2021 3:26:59 PM net.dv8tion.jda.internal.JDAImpl login
INFO: Login Successful!
juin 16, 2021 3:26:59 PM net.dv8tion.jda.internal.requests.WebSocketClient onConnected
INFO: Connected to WebSocket
juin 16, 2021 3:26:59 PM net.dv8tion.jda.api.sharding.DefaultShardManager buildInstance
INFO: Login Successful!
juin 16, 2021 3:26:59 PM net.dv8tion.jda.internal.requests.WebSocketClient handleDisconnect
SEVERE: WebSocket connection was closed and cannot be recovered due to identification issues
CloseCode(4014 / Disallowed intents. Your bot might not be eligible to request a privileged intent such as GUILD_PRESENCES or GUILD_MEMBERS.)
juin 16, 2021 3:27:00 PM net.dv8tion.jda.internal.requests.WebSocketClient onConnected
INFO: Connected to WebSocket
juin 16, 2021 3:27:04 PM net.dv8tion.jda.internal.requests.WebSocketClient handleReconnect
SEVERE: Encountered IDENTIFY Rate Limit!
juin 16, 2021 3:27:04 PM net.dv8tion.jda.internal.requests.WebSocketClient handleReconnect
WARNING: Got disconnected from WebSocket (Code 1000). Appending to reconnect queue
juin 16, 2021 3:27:12 PM net.dv8tion.jda.internal.requests.WebSocketClient onConnected
INFO: Connected to WebSocket
juin 16, 2021 3:27:12 PM net.dv8tion.jda.internal.requests.WebSocketClient ready
INFO: Finished Loading!

And here is my code:
B4X:
Sub AppStart (Args() As String)
    Dim jda As JDA
    Dim b As JDABuilder
    b.Initialize("JDA", config.bottoken)
    b.setAutoReconnect(True).setEnableShutdownHook(True)
    b.setToken(config.bottoken)
  
    jda.Initialize("JDA",b.build)
    
    Dim sh As DefaultShardManagerBuilder
    sh.Initialize2("ShardManager", config.bottoken)
    sh.setToken(config.bottoken)
    sh.build
    StartMessageLoop
    jda.awaitReady
End Sub

Private Sub JDA_onReady
    Log("rdy?")
End Sub

Private Sub JDA_onMessageReceived(event As Object)
    Log("on message")
    Dim ev As MessageReceivedEvent = event
    Dim msg As Message = ev.Message
    Dim ch As MessageChannel = msg.Channel
    
    Dim msgcontent As String = msg.ContentStripped
    If msgcontent = "!ping" Then
        ch.sendMessage("PONG !")
    End If
    
End Sub
But I can't find anything in the logs ("rdy?" & "on message")
 

DonManfred

Expert
Licensed User
Longtime User
Startmessageloop is only useful in a NON UI App. I can´t really help on NON UI apps as i nevr build one.

Try move it after the jda.awaitready or REMOVE it at all.

As written i am using this lib in a UI App. No StartMessageLoop is needed in this case.
 
Last edited:
Upvote 0
Top