-
-
Save nkomarn/4b437fd54b40fed74b37412f17ebac41 to your computer and use it in GitHub Desktop.
package techtoolbox.Bot; | |
import javax.security.auth.login.LoginException; | |
import net.dv8tion.jda.core.JDABuilder; | |
import net.dv8tion.jda.core.OnlineStatus; | |
import net.dv8tion.jda.core.entities.Game; | |
import techtoolbox.Bot.events.GuildMessageReceived; | |
public class Bot { | |
public static String prefix = "~"; | |
public static void main(String[] args) throws LoginException { | |
JDABuilder builder = new JDABuilder(); | |
builder.setToken("Your token goes here."); | |
builder.setStatus(OnlineStatus.ONLINE); | |
builder.setGame(Game.playing("boring comedy shows.")); | |
// Register listeners | |
builder.addEventListener(new GuildMessageReceived()); | |
builder.build(); | |
} | |
} |
Hi, could you update this for JDA 4.2.0?
I have a problem where the net.dv8tion.jda.core.JDABuilder cannot be resolved. then when I switch "core" to "api" the problem is resolved but i get a warning where it says that the JDABuilder constructor is deprecated. any fixes?
I have a problem where the net.dv8tion.jda.core.JDABuilder cannot be resolved. then when I switch "core" to "api" the problem is resolved but i get a warning where it says that the JDABuilder constructor is deprecated. any fixes?
Hey bro! Just managed to find a way around this, these are the 4 lines of code within my main function:
JDA jda = JDABuilder.createDefault(YOUR_TOKEN).build();
jda.getPresence().setStatus(OnlineStatus.ONLINE);
jda.getPresence().setActivity(Activity.listening("commands"));
jda.addEventListener(new Commands());
This should work as I've followed the video and only changed these few lines to ensure it works with 4.2.0; let me know if it works for you 👍
I have a problem where the net.dv8tion.jda.core.JDABuilder cannot be resolved. then when I switch "core" to "api" the problem is resolved but i get a warning where it says that the JDABuilder constructor is deprecated. any fixes?
Hey bro! Just managed to find a way around this, these are the 4 lines of code within my main function:
JDA jda = JDABuilder.createDefault(YOUR_TOKEN).build(); jda.getPresence().setStatus(OnlineStatus.ONLINE); jda.getPresence().setActivity(Activity.listening("commands")); jda.addEventListener(new Commands());This should work as I've followed the video and only changed these few lines to ensure it works with 4.2.0; let me know if it works for you 👍
Hey! thanks so much for the help, nothing is deprecated, BUT when I try to run the code to get the bot to come online i get a NoClassDefFoundError, what could this be caused by?
(snopchops is my bot name)heres the console:
Exception in thread "main" java.lang.NoClassDefFoundError: okhttp3/RequestBody
at net.dv8tion.jda.api.JDABuilder.build(JDABuilder.java:1831)
at snopchopscode.snopchops.main(snopchops.java:14)
Caused by: java.lang.ClassNotFoundException: okhttp3.RequestBody
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
I got the same as the guy above me :(
Same problem here, NoClassDefFoundError. Any solution yet?
I have a problem where the net.dv8tion.jda.core.JDABuilder cannot be resolved. then when I switch "core" to "api" the problem is resolved but i get a warning where it says that the JDABuilder constructor is deprecated. any fixes?
Hey bro! Just managed to find a way around this, these are the 4 lines of code within my main function:
JDA jda = JDABuilder.createDefault(YOUR_TOKEN).build(); jda.getPresence().setStatus(OnlineStatus.ONLINE); jda.getPresence().setActivity(Activity.listening("commands")); jda.addEventListener(new Commands());This should work as I've followed the video and only changed these few lines to ensure it works with 4.2.0; let me know if it works for you 👍
Hey! thanks so much for the help, nothing is deprecated, BUT when I try to run the code to get the bot to come online i get a NoClassDefFoundError, what could this be caused by?
(snopchops is my bot name)heres the console:
Exception in thread "main" java.lang.NoClassDefFoundError: okhttp3/RequestBody
at net.dv8tion.jda.api.JDABuilder.build(JDABuilder.java:1831)
at snopchopscode.snopchops.main(snopchops.java:14)
Caused by: java.lang.ClassNotFoundException: okhttp3.RequestBody
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Ok I solved the problem by importing the -withDependencies.jar rather than the normal one.
help it says "game string"
I got the same as the guy above me :(
when you add JDA as a dependancy make sure you add the one with inbuild dependancies, https://github.com/DV8FromTheWorld/JDA/releases/download/v4.2.0/JDA-4.2.0_168-withDependencies.jar
i have linked it
https://discordapp.com/api/oauth2/authorize?client_id=556131147541643275&permissions=8&redirect_uri=https%3A%2F%2Fdiscord.gg%2FM6gwQz&scope=bot