I saw @DonManfred 's discord api for b4j. I tried to compile using the demo code and got this error while compiling:
error:
javac 1.8.0_271
src\b4j\example\main.java:55: error: cannot access JDAwrapper
de.donmanfred.JDAwrapper _jda = null;
^
bad class file: F:\additional bbl b4j\jda.jar(de/donmanfred/JDAwrapper.class)
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
1 error
Thanks ! Using java 16 it compiles. Now i'm getting this error
error:
Waiting for debugger to connect...
Program started.
java.lang.NoSuchMethodError: 'void net.dv8tion.jda.api.JDABuilder.<init>(java.lang.String)'
at de.donmanfred.JDABuilderwrapper.Initialize2(JDABuilderwrapper.java:71)
at b4j.example.main._appstart(main.java:70)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at b4j.example.main.main(main.java:29)
java.lang.RuntimeException: java.lang.NoSuchMethodError: 'void net.dv8tion.jda.api.JDABuilder.<init>(java.lang.String)'
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:137)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at b4j.example.main.main(main.java:29)
Caused by: java.lang.NoSuchMethodError: 'void net.dv8tion.jda.api.JDABuilder.<init>(java.lang.String)'
at de.donmanfred.JDABuilderwrapper.Initialize2(JDABuilderwrapper.java:71)
at b4j.example.main._appstart(main.java:70)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
Program terminated (StartMessageLoop was not called).
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
... 3 more
Code:
Code:
Sub Process_Globals
Dim sh As DefaultShardManagerBuilder
End Sub
Sub AppStart (Args() As String)
Dim jda As JDA
Dim b As JDABuilder
b.Initialize2("bot", config.bottoken) ' String token from Developersite
b.setAutoReconnect(True).setEnableShutdownHook(True)
jda.Initialize("bot",b.build)
Dim j As BotActivity
j.watching("test")
sh.setactivity(j)
sh.Initialize("ShardManager")
sh.setToken(config.bottoken)
sh.build
jda.awaitReady
End Sub
Sub bot_onMessageReceived(event As Object)
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
Are you building a nonui app? Did you forget to call StartMessageLoop?
Do not use any code other than this in AppStart.
Especially BotActivity. It can only be called after you got the Event JDA_onReady called.
B4X:
Dim b As JDABuilder
b.Initialize("JDA",token)
b.setAutoReconnect(True).setEnableShutdownHook(True)
b.setToken(token)
jda.Initialize("JDA",b.build)
Dim sh As DefaultShardManagerBuilder
sh.Initialize("ShardManager",token)
sh.setToken(token)
sh.build
jda.awaitReady
Under the hood i think you need a new jda-lib and also an updated jda.jar. The one from the example it really old now.
Away from that you should create a new thread for any new question/problem. One thread should summarize one Problem.
With the updated version, It gets better, but still crashes (after login)
B4X:
Waiting for debugger to connect...
Program started.
juin 16, 2021 2:57:54 PM net.dv8tion.jda.internal.JDAImpl login
INFO: Login Successful!
java.lang.NoSuchMethodError: 'void com.neovisionaries.ws.client.WebSocketFactory.<init>(com.neovisionaries.ws.client.WebSocketFactory)'
at net.dv8tion.jda.internal.requests.WebSocketClient.connect(WebSocketClient.java:367)
at net.dv8tion.jda.internal.requests.WebSocketClient$StartingNode.run(WebSocketClient.java:1396)
at net.dv8tion.jda.api.utils.ConcurrentSessionController$Worker.processQueue(ConcurrentSessionController.java:155)
at net.dv8tion.jda.api.utils.ConcurrentSessionController$Worker.run(ConcurrentSessionController.java:133)
at java.base/java.lang.Thread.run(Thread.java:831)
juin 16, 2021 2:57:54 PM net.dv8tion.jda.api.sharding.DefaultShardManager buildInstance
INFO: Login Successful!
java.lang.NoSuchMethodError: 'void com.neovisionaries.ws.client.WebSocketFactory.<init>(com.neovisionaries.ws.client.WebSocketFactory)'
at net.dv8tion.jda.internal.requests.WebSocketClient.connect(WebSocketClient.java:367)
at net.dv8tion.jda.internal.requests.WebSocketClient$StartingNode.run(WebSocketClient.java:1396)
at net.dv8tion.jda.api.utils.ConcurrentSessionController$Worker.processQueue(ConcurrentSessionController.java:155)
at net.dv8tion.jda.api.utils.ConcurrentSessionController$Worker.run(ConcurrentSessionController.java:133)
at java.base/java.lang.Thread.run(Thread.java:831)