HidekoBot/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java

56 lines
1.7 KiB
Java
Raw Normal View History

package wtf.beatrice.hidekobot;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
2022-08-25 22:18:36 +02:00
import net.dv8tion.jda.api.entities.Activity;
2022-08-25 22:13:39 +02:00
import wtf.beatrice.hidekobot.utils.Logger;
import javax.security.auth.login.LoginException;
public class HidekoBot
{
2022-08-25 22:13:39 +02:00
private static Logger logger = new Logger(HidekoBot.class);
2022-08-25 22:20:05 +02:00
private static String botToken;
private static String standardInviteLink = "https://discord.com/oauth2/authorize?client_id=%userid%&scope=bot&permissions=8";
private static String botUserId;
public static void main(String[] args)
{
2022-08-25 22:20:05 +02:00
// check if bot token was specified as a startup argument
if(args.length < 1)
{
logger.log("Please specify your bot token!");
return;
}
botToken = args[0];
2022-08-25 22:18:36 +02:00
JDABuilder jdaBuilder;
JDA jda;
try
{
2022-08-25 22:37:32 +02:00
// try to create the bot object and authenticate it with discord.
2022-08-25 22:20:05 +02:00
jdaBuilder = JDABuilder.createDefault(botToken);
2022-08-25 22:18:36 +02:00
jdaBuilder.setActivity(Activity.playing("the piano"));
jda = jdaBuilder.build();
} catch (LoginException e)
{
2022-08-25 22:37:32 +02:00
logger.log(e.getMessage()); // print the error message, omit the stack trace.
return; // if we failed connecting and authenticating, then quit.
}
2022-08-25 22:37:32 +02:00
// find the bot's user id and generate an invite-link.
botUserId = jda.getSelfUser().getId();
standardInviteLink = standardInviteLink.replace("%userid%", botUserId);
2022-08-25 22:37:32 +02:00
// log the invite-link to console so noob users can just click on it.
logger.log("Bot User ID: " + botUserId, 10);
logger.log("Invite Link: " + standardInviteLink, 10);
2022-08-25 22:18:36 +02:00
}
2022-08-25 22:13:39 +02:00
}