For those who are looking for the information about Discord API Java, in this article, you will be informed to build a really basic bot with the JDA Discord API wrapper. In this tutorial, the IntelliJ IDEA IDE will be used. This one was created by Jetbrains.
The first thing that you have to do is to download and install the thing called IDEA. Please keep in mind that the community edition is enough. Once you open IDEA, you will be able to see the welcoming screen entitled IntelliJ IDEA. Please click on Create New Project, then choose Gradle and mark just Java. The next thing that you have to do is to select the group and artifact ID, they can be anything that you want, but usually the group Id is the reverse of the domain you have, so something like mywebsite.com bcomes com.mywebsite and the artifact ID is the identifier for the project, such as my-jda-bot. Fortunately, do you not need to change any gradle settings, but some people personally like to enable auto import.
After that step, select the project name and where to save it and then click on Finish. Please wait for the gradle to finish configuring your project and you will be able to see the grey screen. Then, open build.gradle and add JDA as the dependency. If there is a dialog showing up, please click Import Changes. Apparently, this one will not show up if you enabled auto import. Now, it is time for you to create the main class. You have to open in the file viewer “src/main” and right click on “java”, then go to New -> Java Class. Then, give the main class a named and click on OK. After that, you will create the main method. In this step, you can type “psvm” until a popup shows and then hit enter.
In the step 6, you will create the JDA instance using the thing called JDABuilder class. In order to continue, you need to have a Discord bot token. You can add the token to the JDABuilder using the “setToken(string) method. Step 7 is the time for you to log in to Discord with your bot. In order to build the JDA instance and connect to Discord, you can just simply call the method “JDABuilder#nuildAsync ()”. Apparently, you will be able to see the red line and wonder what is it. If you hover the mouse above it, you will be able to see the message explaining what is wrong. From now, you can just declare the main method as “throws LoginException”. Then, click the green play button to the left of the class name and choose “Run”.
In order to have your bot do something, you need to add a listener to the JDA instance. From now, you can have the main class extend “ListenerAdapter” and override the onMessageReceive method. He next thing that you can do is to make it reply with “Pong!” if the message is !ping. In the last step, you can register a new instance of the main class in the JDABuilder.