Class CoreSlashCommandHandler

java.lang.Object
net.dv8tion.jda.api.hooks.ListenerAdapter
io.github.yusufsdiscordbot.yusufsdiscordcore.bot.handlers.CoreSlashCommandHandler
All Implemented Interfaces:
net.dv8tion.jda.api.hooks.EventListener
Direct Known Subclasses:
ExampleCommandHandler

@Authors(namesOfTheAuthors={"Yusuf Arfan Ismail","Serkwi Bruno Ndzi"}, namesOfTheAuthorsGithub={"RealYusufIsmail","nDZIB"}) public abstract class CoreSlashCommandHandler extends net.dv8tion.jda.api.hooks.ListenerAdapter
For register the commands make sure to set it to awaitReady as seen here
 jda.awaitReady()
     .addEventListener(new CommandHandler(jda, jda.getGuildById(872494635757473932L)));
 

The is class which process the registration of the commands.

Commands are register by using a List with an example for registering slash commands being

 List handler = new ArrayList<>(); 
handler.add(new ExampleCommand());
queueAndRegisterSlashCommands(handler);
In oder to do other you can do on of the following:
     //slash command
     List slashCommand = new ArrayList<>(); 
//User Command List userCommand = new ArrayList<>();
//Message Command List messageCommand = new ArrayList<>();
slashCommand.add(new ExampleCommand());
queueAndRegisterCommands(slashCommand, userCommand, messageCommand);
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    CoreSlashCommandHandler(@NotNull net.dv8tion.jda.api.JDA jda, @NotNull net.dv8tion.jda.api.entities.Guild guild)
    For an example please see ExampleCommandHandler(JDA, Guild)
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract long
     
    Gets message commands as a list.
    @NotNull List<SlashCommand>
    Gets slash commands as a list.
    @NotNull List<UserCommand>
    Gets user commands as a list.
    void
    onSlashCommandInteraction(@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent slashCommandEvent)
    Handles the slash command event.
    void
    queueAndRegisterCommands(@NotNull Collection<SlashCommand> commands, @NotNull Collection<UserCommand> userCommands, @NotNull Collection<MessageCommand> messageCommands)
    Used to register the slash commands.
    void
    Used to register the message context commands.
    void
    Used to register the slash commands.
    void
    Used to register the user commands.

    Methods inherited from class net.dv8tion.jda.api.hooks.ListenerAdapter

    onButtonInteraction, onChannelCreate, onChannelDelete, onChannelUpdateArchived, onChannelUpdateArchiveTimestamp, onChannelUpdateAutoArchiveDuration, onChannelUpdateBitrate, onChannelUpdateInvitable, onChannelUpdateLocked, onChannelUpdateName, onChannelUpdateNSFW, onChannelUpdateParent, onChannelUpdatePosition, onChannelUpdateRegion, onChannelUpdateSlowmode, onChannelUpdateTopic, onChannelUpdateType, onChannelUpdateUserLimit, onCommandAutoCompleteInteraction, onDisconnect, onEmoteAdded, onEmoteRemoved, onEmoteUpdateName, onEmoteUpdateRoles, onEvent, onException, onGatewayPing, onGenericAutoCompleteInteraction, onGenericChannel, onGenericChannelUpdate, onGenericCommandInteraction, onGenericComponentInteractionCreate, onGenericContextInteraction, onGenericEmote, onGenericEmoteUpdate, onGenericEvent, onGenericGuild, onGenericGuildInvite, onGenericGuildMember, onGenericGuildMemberUpdate, onGenericGuildUpdate, onGenericGuildVoice, onGenericInteractionCreate, onGenericMessage, onGenericMessageReaction, onGenericPermissionOverride, onGenericRole, onGenericRoleUpdate, onGenericSelfUpdate, onGenericStageInstance, onGenericStageInstanceUpdate, onGenericThread, onGenericThreadMember, onGenericUpdate, onGenericUser, onGenericUserPresence, onGuildAvailable, onGuildBan, onGuildInviteCreate, onGuildInviteDelete, onGuildJoin, onGuildLeave, onGuildMemberJoin, onGuildMemberRemove, onGuildMemberRoleAdd, onGuildMemberRoleRemove, onGuildMemberUpdate, onGuildMemberUpdateAvatar, onGuildMemberUpdateBoostTime, onGuildMemberUpdateNickname, onGuildMemberUpdatePending, onGuildMemberUpdateTimeOut, onGuildReady, onGuildTimeout, onGuildUnavailable, onGuildUnban, onGuildUpdateAfkChannel, onGuildUpdateAfkTimeout, onGuildUpdateBanner, onGuildUpdateBoostCount, onGuildUpdateBoostTier, onGuildUpdateCommunityUpdatesChannel, onGuildUpdateDescription, onGuildUpdateExplicitContentLevel, onGuildUpdateFeatures, onGuildUpdateIcon, onGuildUpdateLocale, onGuildUpdateMaxMembers, onGuildUpdateMaxPresences, onGuildUpdateMFALevel, onGuildUpdateName, onGuildUpdateNotificationLevel, onGuildUpdateNSFWLevel, onGuildUpdateOwner, onGuildUpdateRulesChannel, onGuildUpdateSplash, onGuildUpdateSystemChannel, onGuildUpdateVanityCode, onGuildUpdateVerificationLevel, onGuildVoiceDeafen, onGuildVoiceGuildDeafen, onGuildVoiceGuildMute, onGuildVoiceJoin, onGuildVoiceLeave, onGuildVoiceMove, onGuildVoiceMute, onGuildVoiceRequestToSpeak, onGuildVoiceSelfDeafen, onGuildVoiceSelfMute, onGuildVoiceStream, onGuildVoiceSuppress, onGuildVoiceUpdate, onGuildVoiceVideo, onHttpRequest, onMessageBulkDelete, onMessageContextInteraction, onMessageDelete, onMessageEmbed, onMessageReactionAdd, onMessageReactionRemove, onMessageReactionRemoveAll, onMessageReactionRemoveEmote, onMessageReceived, onMessageUpdate, onPermissionOverrideCreate, onPermissionOverrideDelete, onPermissionOverrideUpdate, onRawGateway, onReady, onReconnected, onResumed, onRoleCreate, onRoleDelete, onRoleUpdateColor, onRoleUpdateHoisted, onRoleUpdateIcon, onRoleUpdateMentionable, onRoleUpdateName, onRoleUpdatePermissions, onRoleUpdatePosition, onSelectMenuInteraction, onSelfUpdateAvatar, onSelfUpdateMFA, onSelfUpdateName, onSelfUpdateVerified, onShutdown, onStageInstanceCreate, onStageInstanceDelete, onStageInstanceUpdatePrivacyLevel, onStageInstanceUpdateTopic, onStatusChange, onThreadHidden, onThreadMemberJoin, onThreadMemberLeave, onThreadRevealed, onUnavailableGuildJoined, onUnavailableGuildLeave, onUserActivityEnd, onUserActivityStart, onUserContextInteraction, onUserTyping, onUserUpdateActivities, onUserUpdateActivityOrder, onUserUpdateAvatar, onUserUpdateDiscriminator, onUserUpdateFlags, onUserUpdateName, onUserUpdateOnlineStatus

    Methods inherited from class java.lang.Object

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

    • CoreSlashCommandHandler

      protected CoreSlashCommandHandler(@NotNull @NotNull net.dv8tion.jda.api.JDA jda, @NotNull @NotNull net.dv8tion.jda.api.entities.Guild guild)
      For an example please see ExampleCommandHandler(JDA, Guild)
  • Method Details

    • botOwnerId

      protected abstract long botOwnerId()
      Returns:
      used to set the bot owner id.
    • queueAndRegisterCommands

      public void queueAndRegisterCommands(@NotNull @NotNull Collection<SlashCommand> commands, @NotNull @NotNull Collection<UserCommand> userCommands, @NotNull @NotNull Collection<MessageCommand> messageCommands)
      Used to register the slash commands.
      Parameters:
      commands - The slash commands
    • queueAndRegisterUserCommands

      public void queueAndRegisterUserCommands(@NotNull @NotNull Collection<UserCommand> userCommands)
      Used to register the user commands.
      Parameters:
      userCommands - The user commands.
    • queueAndRegisterSlashCommands

      public void queueAndRegisterSlashCommands(@NotNull @NotNull Collection<SlashCommand> slashCommands)
      Used to register the slash commands.
      Parameters:
      slashCommands - the slash commands.
    • queueAndRegisterMessageContextCommands

      public void queueAndRegisterMessageContextCommands(@NotNull @NotNull Collection<MessageCommand> messageCommand)
      Used to register the message context commands.
      Parameters:
      messageCommand - the message context command.
    • onSlashCommandInteraction

      public void onSlashCommandInteraction(@NotNull @NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent slashCommandEvent)
      Handles the slash command event.
      Overrides:
      onSlashCommandInteraction in class net.dv8tion.jda.api.hooks.ListenerAdapter
      Parameters:
      slashCommandEvent - The original slash command event,
    • getSlashCommands

      @NotNull public @NotNull List<SlashCommand> getSlashCommands()
      Gets slash commands as a list.
      Returns:
      retrieves the commands as a list.
    • getUserCommands

      @NotNull public @NotNull List<UserCommand> getUserCommands()
      Gets user commands as a list.
      Returns:
      retrieves the commands as a list.
    • getMessageCommands

      @NotNull public @NotNull List<MessageCommand> getMessageCommands()
      Gets message commands as a list.
      Returns:
      retrieves the commands as a list.