因此,我已经使该机器人的代码也可以工作,并且可以回答命令,但是我实际上也需要调用它来使其正常工作,所以我不知道该怎么做,我看过Wiki,但相对而言Java也太新了,令人困惑。
我尝试做DiscordBot.jda。并查看可用的方法但看不到什么-我将包括整个机器人的代码
public class DiscordBot extends ListenerAdapter {
public static JDA jda;
public void initialize() {
JDABuilder builder = new JDABuilder(AccountType.BOT);
builder.setStatus(OnlineStatus.ONLINE);
builder.setToken("");
builder.addEventListeners(this);
try {
jda = builder.build();
} catch (LoginException e) {
e.printStackTrace();
}
}
private final String PREFIX = "::";
@Override
public void onMessageReceived(MessageReceivedEvent event) {
String message = event.getMessage().getContentDisplay();
String[] command = message.split("-");
if (command[0].equalsIgnoreCase(PREFIX + "players")) {
event.getChannel().sendMessage("There are currently " + World.getPlayers().size() + " players online.")
.queue();
EmbedBuilder embed = new EmbedBuilder();
embed.setTitle("Naxos!");
embed.setColor(Color.DARK_GRAY);
embed.setDescription("");
embed.addField("There are currently " + World.getPlayers().size() + " online!", "", false);
event.getChannel().sendMessage(embed.build()).queue();
}
if (command[0].equalsIgnoreCase(PREFIX + "vote")) {
EmbedBuilder embed = new EmbedBuilder();
embed.setTitle("Naxos Voting!");
embed.setColor(Color.DARK_GRAY);
embed.setDescription("");
embed.addField("Do ::vote in-game", "", false);
embed.addField("Or head too http://.net/vote", "", false);
embed.addField("Vote on all the sites", "", false);
embed.addField("Do ::rewards 1 all", "", false);
event.getChannel().sendMessage(embed.build()).queue();
}
if (command[0].equalsIgnoreCase(PREFIX + "store")) {
EmbedBuilder embed = new EmbedBuilder();
embed.setTitle("Naxos Voting!");
embed.setColor(Color.DARK_GRAY);
embed.setDescription("");
embed.addField("Do ::donate in-game", "", false);
embed.addField("Or head too http://.net/store", "", false);
embed.addField("Purchase whatever you would like", "", false);
embed.addField("Do ::claim in-game!", "", false);
event.getChannel().sendMessage(embed.build()).queue();
}
if (command[0].equalsIgnoreCase(PREFIX + "website")) {
EmbedBuilder embed = new EmbedBuilder();
embed.setTitle("Naxos Website");
embed.setColor(Color.DARK_GRAY);
embed.setDescription("");
embed.addField(event.getMember().getAsMention() + " http://.net", "", false);
event.getChannel().sendMessage(embed.build()).queue();
}
if (command[0].equalsIgnoreCase(PREFIX + "discordcommands")) {
System.out.println("Command executed");
EmbedBuilder embed = new EmbedBuilder();
embed.setTitle("Naxos commands");
embed.setColor(Color.RED);
embed.setDescription("");
embed.addField("::store", "", false);
embed.addField("::players", "", false);
embed.addField("::vote", "", false);
embed.addField("::website", "", false);
event.getChannel().sendMessage(embed.build()).queue();
}
}
}
我也需要在我的主要方法中调用该bot,我相信它也可以使它起作用,我只是不知道如何通过使用不同的方法来调用它。
答案 0 :(得分:0)
您没有实际启动应用程序的主要方法,请将其添加到您的类中以使其启动您的机器人。
public static void main(String[] args) {
new DiscordBot().initialize();
}