10/9/2018 - 10:37 PM


For Episode 2:

Discord Developer Portal: Java Discord API(JDA):

package events;

import net.dv8tion.jda.core.hooks.ListenerAdapter;

public class PM extends ListenerAdapter {

    //You can pretty much find an event for everything. Here's another example.
    public void onCategoryCreate(CategoryCreateEvent e){

package events;
import net.dv8tion.jda.core.hooks.ListenerAdapter;

public class HelloEvent extends ListenerAdapter {

//    public void onGuildMessageReceived(GuildMessageReceivedEvent event){
//        String messageSent = event.getMessage().getContentRaw(); //Get's the event's message as a raw string and stores it into a string
//        if (messageSent.equalsIgnoreCase("hello")){ //Checks to see what the message is
//            event.getChannel().sendMessage("hello").queue(); //Sends a message to the channel that the bot received the message from. Queue must be used to queue bot actions
//        }
//    }

    //a more advanced example
    public void onGuildMessageReceived(GuildMessageReceivedEvent e){
        String[] args = e.getMessage().getContentRaw().split(" ");
        String name = e.getMember().getUser().getName(); //Get the name of the user who sent the message
            if(!e.getMember().getUser().isBot()){ //Checks to see if the user who triggered the event is a bot or not. This prevents an endless loop of the message hi being sent.
                e.getChannel().sendMessage("hi " + name).queue(); //Say hi plus their name
import events.HelloEvent;
import events.AnotherEvent;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;

public class App {

    public static void main(String args[]) throws Exception{

        JDA jda = new JDABuilder("yourtoken").build();

        //Register our events
        jda.addEventListener(new HelloEvent());
        jda.addEventListener(new AnotherEvent());