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
ConstructorsConstructorDescriptionDIH4JDA(DIH4JDAConfig config) Constructs a new DIH4JDA instance using the specifiedDIH4JDAConfig. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddButtonMappings(IdMapping<ButtonHandler>... mappings) voidaddContextCommands(ContextCommand<?>... commands) Manually registersContextCommands.final voidaddEntitySelectMenuMappings(IdMapping<EntitySelectMenuHandler>... mappings) Binds allEntitySelectMenuHandlers to their id,voidaddEventListener(Object... classes) Allows to registerevent listenerclasses.final voidaddModalMappings(IdMapping<ModalHandler>... mappings) Binds allModalHandlers to their id.voidaddSlashCommands(SlashCommand... commands) Manually registersSlashCommands.final voidaddStringSelectMenuMappings(IdMapping<StringSelectMenuHandler>... mappings) Binds allStringSelectMenuHandlers to their id.final IdMapping<ButtonHandler>[]Gets allButtonHandlers.TheDIH4JDAConfigthat is used by this specificDIH4JDAinstance.static RegistrationTypeGets the defaultRegistrationType.final IdMapping<EntitySelectMenuHandler>[]Gets all registeredEntitySelectMenuHandlers.Gets allDIH4JDAEventListeners that were previously added usingaddEventListener(Object...).net.dv8tion.jda.api.JDAgetJDA()Gets theJDAinstanceDIH4JDAuses.final IdMapping<ModalHandler>[]Gets allModalHandlers.final IdMapping<StringSelectMenuHandler>[]Gets all registeredStringSelectMenuHandlers.voidonReady(net.dv8tion.jda.api.events.session.ReadyEvent event) Ran once theJDAinstance fires theReadyEvent.voidRegisters all Interactions and replaces the old ones.static voidSets the defaultRegistrationTypefor allApplication Commands.Methods inherited from class net.dv8tion.jda.api.hooks.ListenerAdapter
onApplicationCommandUpdatePrivileges, onApplicationUpdatePrivileges, onButtonInteraction, onChannelCreate, onChannelDelete, onChannelUpdateAppliedTags, onChannelUpdateArchived, onChannelUpdateArchiveTimestamp, onChannelUpdateAutoArchiveDuration, onChannelUpdateBitrate, onChannelUpdateDefaultReaction, onChannelUpdateDefaultThreadSlowmode, onChannelUpdateFlags, onChannelUpdateInvitable, onChannelUpdateLocked, onChannelUpdateName, onChannelUpdateNSFW, onChannelUpdateParent, onChannelUpdatePosition, onChannelUpdateRegion, onChannelUpdateSlowmode, onChannelUpdateTopic, onChannelUpdateType, onChannelUpdateUserLimit, onCommandAutoCompleteInteraction, onEmojiAdded, onEmojiRemoved, onEmojiUpdateName, onEmojiUpdateRoles, onEntitySelectInteraction, onEvent, onException, onForumTagAdd, onForumTagRemove, onForumTagUpdateEmoji, onForumTagUpdateModerated, onForumTagUpdateName, onGatewayPing, onGenericAutoCompleteInteraction, onGenericChannel, onGenericChannelUpdate, onGenericCommandInteraction, onGenericComponentInteractionCreate, onGenericContextInteraction, onGenericEmoji, onGenericEmojiUpdate, onGenericEvent, onGenericForumTag, onGenericForumTagUpdate, onGenericGuild, onGenericGuildInvite, onGenericGuildMember, onGenericGuildMemberUpdate, onGenericGuildSticker, onGenericGuildStickerUpdate, onGenericGuildUpdate, onGenericGuildVoice, onGenericInteractionCreate, onGenericMessage, onGenericMessageReaction, onGenericPermissionOverride, onGenericPrivilegeUpdate, onGenericRole, onGenericRoleUpdate, onGenericScheduledEventUpdate, onGenericSelectMenuInteraction, onGenericSelfUpdate, onGenericSessionEvent, onGenericStageInstance, onGenericStageInstanceUpdate, onGenericThread, onGenericThreadMember, onGenericUpdate, onGenericUser, onGenericUserPresence, onGuildAvailable, onGuildBan, onGuildInviteCreate, onGuildInviteDelete, onGuildJoin, onGuildLeave, onGuildMemberJoin, onGuildMemberRemove, onGuildMemberRoleAdd, onGuildMemberRoleRemove, onGuildMemberUpdate, onGuildMemberUpdateAvatar, onGuildMemberUpdateBoostTime, 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, onMessageEmbed, onMessageReactionAdd, onMessageReactionRemove, onMessageReactionRemoveAll, onMessageReactionRemoveEmoji, onMessageReceived, onMessageUpdate, onModalInteraction, onPermissionOverrideCreate, onPermissionOverrideDelete, onPermissionOverrideUpdate, onRawGateway, onRoleCreate, onRoleDelete, onRoleUpdateColor, onRoleUpdateHoisted, onRoleUpdateIcon, onRoleUpdateMentionable, onRoleUpdateName, onRoleUpdatePermissions, onRoleUpdatePosition, onScheduledEventCreate, onScheduledEventDelete, onScheduledEventUpdateDescription, onScheduledEventUpdateEndTime, onScheduledEventUpdateLocation, onScheduledEventUpdateName, onScheduledEventUpdateStartTime, onScheduledEventUpdateStatus, onScheduledEventUserAdd, onScheduledEventUserRemove, onSelfUpdateAvatar, 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, onUserUpdateName, onUserUpdateOnlineStatus
-
Constructor Details
-
DIH4JDA
Constructs a new DIH4JDA instance using the specifiedDIH4JDAConfig. It is highly recommended to use theDIH4JDABuilderinstead.- Parameters:
config- The instance'sconfiguration.- Throws:
DIH4JDAException- if the givenDIH4JDAConfigis invalid.
-
-
Method Details
-
onReady
public void onReady(@Nonnull net.dv8tion.jda.api.events.session.ReadyEvent event) Ran once theJDAinstance fires theReadyEvent.- Overrides:
onReadyin classnet.dv8tion.jda.api.hooks.ListenerAdapter- Parameters:
event- TheReadyEventthat was fired.
-
setDefaultRegistrationType
Sets the defaultRegistrationTypefor allApplication Commands. This is set toRegistrationType.GLOBALif not set otherwise.- Parameters:
type- TheRegistrationType.
-
getDefaultRegistrationType
Gets the defaultRegistrationType.- Returns:
- the
RegistrationType.
-
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. -
getConfig
TheDIH4JDAConfigthat is used by this specificDIH4JDAinstance.- Returns:
- The instance's
configuration.
-
addEventListener
Allows to registerevent listenerclasses.- Parameters:
classes- Implementations ofDIH4JDAEventListener.- Since:
- v1.5
-
getEventListeners
Gets allDIH4JDAEventListeners that were previously added usingaddEventListener(Object...).- Returns:
- A set of all Listener classes.
- See Also:
-
getJDA
@Nonnull public net.dv8tion.jda.api.JDA getJDA()Gets theJDAinstanceDIH4JDAuses.- Returns:
- The
JDAinstance.
-
addSlashCommands
Manually registersSlashCommands.- Parameters:
commands- An array of commands to register.
-
addContextCommands
Manually registersContextCommands.- Parameters:
commands- An array of commands to register.
-
addButtonMappings
Binds allButtonHandlers 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.
-
getButtonMappings
Gets allButtonHandlers.- Returns:
- An
IdMappingarray which contains the never-null ids and handlers.
-
addStringSelectMenuMappings
@SafeVarargs public final void addStringSelectMenuMappings(@Nonnull IdMapping<StringSelectMenuHandler>... mappings) Binds allStringSelectMenuHandlers 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:
-
getStringSelectMenuMappings
Gets all registeredStringSelectMenuHandlers.- Returns:
- An
IdMappingarray which contains the never-null ids and handlers. - See Also:
-
addEntitySelectMenuMappings
@SafeVarargs public final void addEntitySelectMenuMappings(@Nonnull IdMapping<EntitySelectMenuHandler>... mappings) Binds allEntitySelectMenuHandlers 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:
-
getEntitySelectMenuMappings
Gets all registeredEntitySelectMenuHandlers.- Returns:
- An
IdMappingarray which contains the never-null ids and handlers. - See Also:
-
addModalMappings
Binds allModalHandlers 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.
-
getModalMappings
Gets allModalHandlers.- Returns:
- An
IdMappingarray which contains the never-null ids and handlers.
-