Class JavaDiscordBot

java.lang.Object
com.dianxin.tori.api.bot.JavaDiscordBot

public abstract class JavaDiscordBot extends Object
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:

The class also automatically manages:

  • JDA initialization and shutdown
  • Console command listener
  • Presence and intents setup
  • Basic logging flow
Example usage:

 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected net.dv8tion.jda.api.JDABuilder
    Creates and configures the JDABuilder with the bot's intents, activity, and audio module config.
    protected net.dv8tion.jda.api.entities.Activity
    Defines the bot's presence/activity shown on Discord.
    protected net.dv8tion.jda.api.audio.AudioModuleConfig
    Provides dave session if available.
     
    getBotInviteLink(net.dv8tion.jda.api.Permission... permissions)
     
    protected abstract String
    Provides 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.JDA
    The JDA instance representing the bot connection.
    protected @NotNull org.slf4j.Logger
    Logger instance for this bot class.
    @NotNull IBotMeta
     
    final @NotNull Scheduler
     
    net.dv8tion.jda.api.entities.User
     
    protected void
    Called before the bot shuts down.
    protected void
    Called when the bot fully starts and is ready.
    void
    Gracefully shuts down the bot, updating its status to offline, calling onDisable(), and closing the JDA connection.
    protected void
    Deprecated.
    void
    Starts the bot, initializes JDA, loads intents/activity, registers console commands, and begins console listening.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JavaDiscordBot

      public JavaDiscordBot()
  • Method Details

    • getBotToken

      protected abstract String 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

      public void start() throws InterruptedException
      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, calling onDisable(), and closing the JDA connection.
    • getDataFolder

      public File getDataFolder()
    • getIntents

      protected EnumSet<net.dv8tion.jda.api.requests.GatewayIntent> getIntents()
      Provides the list of gateway intents required for the bot.
      Returns:
      An EnumSet of intents or null to use default JDA behavior.
    • getActivity

      protected net.dv8tion.jda.api.entities.Activity getActivity()
      Defines the bot's presence/activity shown on Discord.
      Returns:
      A Activity instance or null for no activity.
    • getAudioModuleConfig

      protected net.dv8tion.jda.api.audio.AudioModuleConfig getAudioModuleConfig()
      Provides dave session if available.
      Returns:
      A AudioModuleConfig.
    • registerConsoleCommands

      @Deprecated protected void registerConsoleCommands()
      Deprecated.
      Override this to register custom console commands using ConsoleCommandManager.
    • 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

      public String getBotInviteLink()
    • getBotInviteLink

      public String getBotInviteLink(net.dv8tion.jda.api.Permission... permissions)
    • getMeta

      @NotNull public @NotNull IBotMeta getMeta()
      Returns:
      Meta of the bot
    • getLogger

      @NotNull protected @NotNull org.slf4j.Logger getLogger()
      Logger instance for this bot class.
    • getScheduler

      @NotNull public final @NotNull Scheduler getScheduler()