Skip to content

Instantly share code, notes, and snippets.

@nkomarn
Created February 2, 2019 16:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkomarn/4b437fd54b40fed74b37412f17ebac41 to your computer and use it in GitHub Desktop.
Save nkomarn/4b437fd54b40fed74b37412f17ebac41 to your computer and use it in GitHub Desktop.
An update for the bot tutorial (when using JDA 3.8)!
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();
}
}
@KingGaming001
Copy link

Hi, could you update this for JDA 4.2.0?

@McJagpipes
Copy link

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?

@CameronMukherjee
Copy link

CameronMukherjee commented Sep 4, 2020

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 👍

@McJagpipes
Copy link

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

@Carlosk12xd
Copy link

I got the same as the guy above me :(

@KarahanS
Copy link

Same problem here, NoClassDefFoundError. Any solution yet?

@KarahanS
Copy link

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.

@Matitron
Copy link

Matitron commented Dec 4, 2020

help it says "game string"

@MOMIN5
Copy link

MOMIN5 commented Feb 2, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment