For Episode 7 of the JDA Tutorial:
https://jda-applications.github.io/JDA-Utilities/ https://github.com/JDA-Applications/JDA-Utilities/wiki/Commands https://github.com/JDA-Applications/JDA-Utilities https://github.com/JDA-Applications/JDA-Utilities/tree/master/command
package me.illuminatiproductions.commands;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import net.dv8tion.jda.core.EmbedBuilder;
import java.awt.*;
import java.util.Arrays;
public class ServerInfo extends Command {
public ServerInfo(){
this.name = "serverinfo";
this.aliases = new String[]{"server"};
this.help = "Gives information about the server.";
}
@Override
protected void execute(CommandEvent event) {
//Makes an array that will hold all of the members
String[] test = new String[event.getGuild().getMembers().size()];
for(int i = 0; i < event.getGuild().getMembers().size();i++){
test[i] = event.getGuild().getMembers().get(i).getEffectiveName();
}
//The Embed with all of the server info
EmbedBuilder eb = new EmbedBuilder();
eb.setColor(Color.RED);
eb.setAuthor(event.getGuild().getName());
eb.setThumbnail("https://static.thenounproject.com/png/937475-200.png");
eb.addField("Server Owner:", event.getGuild().getOwner().getEffectiveName(), true);
eb.addField("Member Count:", Integer.toString(event.getGuild().getMembers().toArray().length), true);
eb.setDescription("**Members:** \n" + Arrays.toString(test) + "\n **Invite link:** \n" + "https://discord.gg/3stGDun");
//
//Sends the embed as a message
event.getChannel().sendMessage(eb.build()).queue();
event.getChannel().sendMessage(event.getAuthor().getAsMention()).queue(); //Mentions the user to get their attention
}
}
package me.illuminatiproductions;
import com.jagrosh.jdautilities.command.CommandClient;
import com.jagrosh.jdautilities.command.CommandClientBuilder;
import me.illuminatiproductions.commands.ServerInfo;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
public class App extends ListenerAdapter {
public static void main(String [] args) throws Exception{
JDA jda = new JDABuilder(AccountType.BOT).setToken("yourtokengoeshere").buildBlocking();
CommandClientBuilder builder = new CommandClientBuilder();
builder.setOwnerId("PutYourBotsIDHEREEEEE");
//command prefix
builder.setPrefix("$");
//Add our command(this is now where we register the commands)
builder.addCommand(new ServerInfo());
//Bot helps u out. its nice
builder.setHelpWord("helpme");
//build the command client
CommandClient client = builder.build();
//We no longer need to register each command class here, we just register the command client
jda.addEventListener(client);
}
}
<dependencies>
<dependency>
<groupId>com.jagrosh</groupId>
<artifactId>jda-utilities</artifactId>
<version>2.1.4</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>3.7.1_386</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>