Package xyz.dynxsty.dih4jda
Class DIH4JDA
java.lang.Object
net.dv8tion.jda.api.hooks.ListenerAdapter
xyz.dynxsty.dih4jda.DIH4JDA
- All Implemented Interfaces:
net.dv8tion.jda.api.hooks.EventListener
public class DIH4JDA
extends net.dv8tion.jda.api.hooks.ListenerAdapter
Getting Started
Creating a new DIH4JDA instance is fairly easy:
DIH4JDA dih4jda = DIH4JDABuilder
.setJDA(jda) // Your JDA instance
.build();
Now, you get to decide how you want your commands to be registered:
Manual Command Registration
To manually register commands, use the following methods, AFTER you've.build();
your DIH4JDA instance, like that:
DIH4JDA dih4jda = DIH4JDABuilder
.setJDA(jda) // Your JDA instance
.build();
dih4jda.addSlashCommands(new PingCommand(), new HelloWorldCommand());
dih4jda.addContextMenus(new PingUserContext(), new HelloWorldMessageContext());
Automatic Command Registration
Alternatively, you can specify packages on theDIH4JDABuilder
instance which will be scanned for all classes that extend one of the following classes:
DIH4JDA dih4jda = DIH4JDABuilder
.setJDA(jda) // Your JDA instance
.setCommandPackages("xyz.dynxsty.bot.commands") // OPTIONAL: The package(s) that contains all your commands
.build();
Upon calling .build();
, the bot will register all commands that are in the specified package(s).-
Constructor Summary
ConstructorDescriptionDIH4JDA
(DIH4JDAConfig config) Constructs a new DIH4JDA instance using the specifiedDIH4JDAConfig
. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addButtonMappings
(IdMapping<ButtonHandler>... mappings) void
addContextCommands
(ContextCommand<?>... commands) Manually registersContextCommand
s.final void
addEntitySelectMenuMappings
(IdMapping<EntitySelectMenuHandler>... mappings) Binds allEntitySelectMenuHandler
s to their id,void
addEventListener
(Object... classes) Allows to registerevent listener
classes.final void
addModalMappings
(IdMapping<ModalHandler>... mappings) Binds allModalHandler
s to their id.void
addSlashCommands
(SlashCommand... commands) Manually registersSlashCommand
s.final void
addStringSelectMenuMappings
(IdMapping<StringSelectMenuHandler>... mappings) Binds allStringSelectMenuHandler
s to their id.net.dv8tion.jda.api.JDA
getJDA()
Gets theJDA
instanceDIH4JDA
uses.void
onReady
(net.dv8tion.jda.api.events.session.ReadyEvent event) Ran once theJDA
instance fires theReadyEvent
.void
Registers all Interactions and replaces the old ones.static void
Sets the defaultRegistrationType
for allApplication Commands
.Methods inherited from class net.dv8tion.jda.api.hooks.ListenerAdapter
onApplicationCommandUpdatePrivileges, onApplicationUpdatePrivileges, onAutoModExecution, onAutoModRuleCreate, onAutoModRuleDelete, onAutoModRuleUpdate, onButtonInteraction, onChannelCreate, onChannelDelete, onChannelUpdateAppliedTags, onChannelUpdateArchived, onChannelUpdateArchiveTimestamp, onChannelUpdateAutoArchiveDuration, onChannelUpdateBitrate, onChannelUpdateDefaultLayout, onChannelUpdateDefaultReaction, onChannelUpdateDefaultSortOrder, onChannelUpdateDefaultThreadSlowmode, onChannelUpdateFlags, onChannelUpdateInvitable, onChannelUpdateLocked, onChannelUpdateName, onChannelUpdateNSFW, onChannelUpdateParent, onChannelUpdatePosition, onChannelUpdateRegion, onChannelUpdateSlowmode, onChannelUpdateTopic, onChannelUpdateType, onChannelUpdateUserLimit, onChannelUpdateVoiceStatus, onCommandAutoCompleteInteraction, onEmojiAdded, onEmojiRemoved, onEmojiUpdateName, onEmojiUpdateRoles, onEntitlementCreate, onEntitlementDelete, onEntitlementUpdate, onEntitySelectInteraction, onEvent, onException, onForumTagAdd, onForumTagRemove, onForumTagUpdateEmoji, onForumTagUpdateModerated, onForumTagUpdateName, onGatewayPing, onGenericAutoCompleteInteraction, onGenericAutoModRule, onGenericChannel, onGenericChannelUpdate, onGenericCommandInteraction, onGenericComponentInteractionCreate, onGenericContextInteraction, onGenericEmoji, onGenericEmojiUpdate, onGenericEntitlement, onGenericEvent, onGenericForumTag, onGenericForumTagUpdate, onGenericGuild, onGenericGuildInvite, onGenericGuildMember, onGenericGuildMemberUpdate, onGenericGuildSticker, onGenericGuildStickerUpdate, onGenericGuildUpdate, onGenericGuildVoice, onGenericInteractionCreate, onGenericMessage, onGenericMessagePollVote, onGenericMessageReaction, onGenericPermissionOverride, onGenericPrivilegeUpdate, onGenericRole, onGenericRoleUpdate, onGenericScheduledEventGateway, onGenericScheduledEventUpdate, onGenericScheduledEventUser, onGenericSelectMenuInteraction, onGenericSelfUpdate, onGenericSession, onGenericStageInstance, onGenericStageInstanceUpdate, onGenericThread, onGenericThreadMember, onGenericUpdate, onGenericUser, onGenericUserPresence, onGenericUserUpdate, onGuildAuditLogEntryCreate, onGuildAvailable, onGuildBan, onGuildInviteCreate, onGuildInviteDelete, onGuildJoin, onGuildLeave, onGuildMemberJoin, onGuildMemberRemove, onGuildMemberRoleAdd, onGuildMemberRoleRemove, onGuildMemberUpdate, onGuildMemberUpdateAvatar, onGuildMemberUpdateBoostTime, onGuildMemberUpdateFlags, onGuildMemberUpdateNickname, onGuildMemberUpdatePending, onGuildMemberUpdateTimeOut, onGuildReady, onGuildStickerAdded, onGuildStickerRemoved, onGuildStickerUpdateAvailable, onGuildStickerUpdateDescription, onGuildStickerUpdateName, onGuildStickerUpdateTags, 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, onGuildVoiceMute, onGuildVoiceRequestToSpeak, onGuildVoiceSelfDeafen, onGuildVoiceSelfMute, onGuildVoiceStream, onGuildVoiceSuppress, onGuildVoiceUpdate, onGuildVoiceVideo, onHttpRequest, onMessageBulkDelete, onMessageContextInteraction, onMessageDelete, onMessagePollVoteAdd, onMessagePollVoteRemove, onMessageReactionAdd, onMessageReactionRemove, onMessageReactionRemoveAll, onMessageReactionRemoveEmoji, onMessageReceived, onMessageUpdate, onModalInteraction, onPermissionOverrideCreate, onPermissionOverrideDelete, onPermissionOverrideUpdate, onRawGateway, onRoleCreate, onRoleDelete, onRoleUpdateColor, onRoleUpdateHoisted, onRoleUpdateIcon, onRoleUpdateMentionable, onRoleUpdateName, onRoleUpdatePermissions, onRoleUpdatePosition, onScheduledEventCreate, onScheduledEventDelete, onScheduledEventUpdateDescription, onScheduledEventUpdateEndTime, onScheduledEventUpdateImage, onScheduledEventUpdateLocation, onScheduledEventUpdateName, onScheduledEventUpdateStartTime, onScheduledEventUpdateStatus, onScheduledEventUserAdd, onScheduledEventUserRemove, onSelfUpdateAvatar, onSelfUpdateDiscriminator, onSelfUpdateGlobalName, onSelfUpdateMFA, onSelfUpdateName, onSelfUpdateVerified, onSessionDisconnect, onSessionInvalidate, onSessionRecreate, onSessionResume, onShutdown, onSlashCommandInteraction, onStageInstanceCreate, onStageInstanceDelete, onStageInstanceUpdatePrivacyLevel, onStageInstanceUpdateTopic, onStatusChange, onStringSelectInteraction, onThreadHidden, onThreadMemberJoin, onThreadMemberLeave, onThreadRevealed, onUnavailableGuildJoined, onUnavailableGuildLeave, onUserActivityEnd, onUserActivityStart, onUserContextInteraction, onUserTyping, onUserUpdateActivities, onUserUpdateActivityOrder, onUserUpdateAvatar, onUserUpdateDiscriminator, onUserUpdateFlags, onUserUpdateGlobalName, onUserUpdateName, onUserUpdateOnlineStatus
-
Constructor Details
-
DIH4JDA
Constructs a new DIH4JDA instance using the specifiedDIH4JDAConfig
. It is highly recommended to use theDIH4JDABuilder
instead.- Parameters:
config
- The instance'sconfiguration
.- Throws:
DIH4JDAException
- if the givenDIH4JDAConfig
is invalid.
-
-
Method Details
-
onReady
public void onReady(@Nonnull net.dv8tion.jda.api.events.session.ReadyEvent event) Ran once theJDA
instance fires theReadyEvent
.- Overrides:
onReady
in classnet.dv8tion.jda.api.hooks.ListenerAdapter
- Parameters:
event
- TheReadyEvent
that was fired.
-
setDefaultRegistrationType
Sets the defaultRegistrationType
for allApplication Commands
. This is set toRegistrationType.GLOBAL
if not set otherwise.- Parameters:
type
- TheRegistrationType
.
-
registerInteractions
public void registerInteractions()Registers all Interactions and replaces the old ones. Please note that global commands may need up to an hour before they're fully registered. -
addEventListener
Allows to registerevent listener
classes.- Parameters:
classes
- Implementations ofDIH4JDAEventListener
.- Since:
- v1.5
-
getJDA
@Nonnull public net.dv8tion.jda.api.JDA getJDA()Gets theJDA
instanceDIH4JDA
uses.- Returns:
- The
JDA
instance.
-
addSlashCommands
Manually registersSlashCommand
s.- Parameters:
commands
- An array of commands to register.
-
addContextCommands
Manually registersContextCommand
s.- Parameters:
commands
- An array of commands to register.
-
addButtonMappings
Binds allButtonHandler
s to their id usingIdMapping
dih4jda.addButtonMappings( IdMapping.of(new PingCommand(), "ping", "hello-world"), IdMapping.of(new DummyCommand(), "dummy", "test") );
This is best used in combination withComponentIdBuilder.build(String, Object...)
.- Parameters:
mappings
- AllButtonHandler
, as an array ofIdMapping
.
-
addStringSelectMenuMappings
@SafeVarargs public final void addStringSelectMenuMappings(@Nonnull IdMapping<StringSelectMenuHandler>... mappings) Binds allStringSelectMenuHandler
s to their id.
dih4jda.addStringSelectMenuMappings( IdMapping.of(new PingCommand(), "ping", "hello-world"), IdMapping.of(new DummyCommand(), "dummy", "test") );
This is best used in combination withComponentIdBuilder.build(String, Object...)
.- Parameters:
mappings
- AllStringSelectMenuHandler
, as an array ofIdMapping
.- See Also:
-
addEntitySelectMenuMappings
@SafeVarargs public final void addEntitySelectMenuMappings(@Nonnull IdMapping<EntitySelectMenuHandler>... mappings) Binds allEntitySelectMenuHandler
s to their id,
dih4jda.addEntitySelectMenuMappings( IdMapping.of(new PingCommand(), "ping", "hello-world"), IdMapping.of(new DummyCommand(), "dummy", "test") );
This is best used in combination withComponentIdBuilder.build(String, Object...)
.- Parameters:
mappings
- AllEntitySelectMenuHandler
, as an array ofIdMapping
.- See Also:
-
addModalMappings
Binds allModalHandler
s to their id.
dih4jda.addModalMappings( IdMapping.of(new PingCommand(), "ping", "hello-world"), IdMapping.of(new DummyCommand(), "dummy", "test") );
This is best used in combination withComponentIdBuilder.build(String, Object...)
.- Parameters:
mappings
- AllModalHandler
, as an array ofIdMapping
.
-