Package com.dianxin.tori.api.bot
Class JavaDiscordBot
java.lang.Object
com.dianxin.tori.api.bot.JavaDiscordBot
Represents a base class for creating Discord bots using JDA with an extended
lifecycle system, console command support, and customizable startup options.
Users of this API should extend this class and override the desired methods such as:
onEnable()- Called after the bot finishes starting.onDisable()- Called before the bot shuts down.registerConsoleCommands()- Register custom console commands.getIntents()- Provide requiredGatewayIntentvalues.getActivity()- Define the bot presence/activity.
The class also automatically manages:
- JDA initialization and shutdown
- Console command listener
- Presence and intents setup
- Basic logging flow
public class MyBot extends JavaDiscordBot {
public MyBot() {
super("YOUR_TOKEN", "MyBot");
}
@Override
public void onEnable() {
getLogger().info("MyBot is ready!");
}
@Override
protected EnumSet<GatewayIntent> getIntents() {
return IntentContext.getDefaultIntents();
}
@Override
protected Activity getActivity() {
return Activity.playing("Hello world!");
}
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected net.dv8tion.jda.api.JDABuilderbuilder()Creates and configures the JDABuilder with the bot's intents, activity, and audio module config.protected net.dv8tion.jda.api.entities.ActivityDefines the bot's presence/activity shown on Discord.protected net.dv8tion.jda.api.audio.AudioModuleConfigProvides dave session if available.getBotInviteLink(net.dv8tion.jda.api.Permission... permissions) protected abstract StringProvides the bot token required for authentication with Discord.protected EnumSet<net.dv8tion.jda.api.requests.GatewayIntent> Provides the list of gateway intents required for the bot.net.dv8tion.jda.api.JDAgetJda()The JDA instance representing the bot connection.protected @NotNull org.slf4j.LoggerLogger instance for this bot class.@NotNull IBotMetagetMeta()final @NotNull Schedulernet.dv8tion.jda.api.entities.UsergetSelf()protected voidCalled before the bot shuts down.protected voidonEnable()Called when the bot fully starts and is ready.voidGracefully shuts down the bot, updating its status to offline, callingonDisable(), and closing the JDA connection.protected voidDeprecated.voidstart()Starts the bot, initializes JDA, loads intents/activity, registers console commands, and begins console listening.
-
Constructor Details
-
JavaDiscordBot
public JavaDiscordBot()
-
-
Method Details
-
getBotToken
Provides the bot token required for authentication with Discord.- Returns:
- The bot token as a string.
-
builder
protected net.dv8tion.jda.api.JDABuilder builder()Creates and configures the JDABuilder with the bot's intents, activity, and audio module config.Subclasses can override this method to further customize the JDABuilder.
- Returns:
- The configured JDABuilder instance.
-
start
Starts the bot, initializes JDA, loads intents/activity, registers console commands, and begins console listening.This method blocks until the JDA session is ready.
- Throws:
InterruptedException- If the current thread is interrupted.
-
onEnable
protected void onEnable()Called when the bot fully starts and is ready. Override to initialize listeners, commands, database, etc. -
onDisable
protected void onDisable()Called before the bot shuts down. Override to close resources or save data. -
onShutdown
public void onShutdown()Gracefully shuts down the bot, updating its status to offline, callingonDisable(), and closing the JDA connection. -
getDataFolder
-
getIntents
Provides the list of gateway intents required for the bot.- Returns:
- An
EnumSetof intents ornullto use default JDA behavior.
-
getActivity
protected net.dv8tion.jda.api.entities.Activity getActivity()Defines the bot's presence/activity shown on Discord.- Returns:
- A
Activityinstance ornullfor no activity.
-
getAudioModuleConfig
protected net.dv8tion.jda.api.audio.AudioModuleConfig getAudioModuleConfig()Provides dave session if available.- Returns:
- A AudioModuleConfig.
-
registerConsoleCommands
Deprecated.Override this to register custom console commands usingConsoleCommandManager. -
getJda
public net.dv8tion.jda.api.JDA getJda()The JDA instance representing the bot connection. -
getSelf
public net.dv8tion.jda.api.entities.User getSelf() -
getBotInviteLink
-
getBotInviteLink
-
getMeta
- Returns:
- Meta of the bot
-
getLogger
@NotNull protected @NotNull org.slf4j.Logger getLogger()Logger instance for this bot class. -
getScheduler
-