-
-
Notifications
You must be signed in to change notification settings - Fork 1
Context Menus
Context menus are an incredible tool to quickly perform an action upon a message or a user, but for awhile, Nexus didn't support it and developers had their context menus overwritten by Nexus due to it using bulkOverwrite
. Although that changes in the recent 1.0.0-next change which added context menus natively into Nexus like regular commands.
Unlike slash commands, Context menus do not support the following:
- Middlewares and afterwares: There is currently no common interface between user and message context menus, so we held off supporting this and the current middleware and afterware system is heavily based for slash commands, so changing it to support context menus requires more effort and many breaking changes.
- Auto-defer: Currently, auto-defer isn't supported, but this may change in the future versions.
To create a context menu, you can extend upon the NexusUserContextMenu
or NexusMessageContextMenu
abstract classes (we use abstract classes as the abstract classes implements necessary methods underneath):
object TestUserContextMenu: NexusUserContextMenu() {
val name = "test"
override fun onEvent(event: NexusContextMenuEvent<UserContextMenuCommandEvent, UserContextMenuInteraction>) {
event.respondNowEphemerallyWith("Hello")
}
}
object TestMessageContextMenu: NexusMessageContextMenu() {
val name = "test"
override fun onEvent(event: NexusContextMenuEvent<MessageContextMenuCommandEvent, MessageContextMenuInteraction>) {
event.respondNowEphemerallyWith("Hello")
}
}
A message and a user context menu can have the same name, and a context menu must have the name
property otherwise the framework will complain when you try to add the context menu using the following method:
Nexus.contextMenus(TestUserContextMenu, TestMessageContextMenu)
After adding the context menus to the registry, everything should work (naturally, after synchronizing them using the same method in Command Synchronization
).
For more information about what properties to override, refer to:
All information in this wiki was written during v1.2.0
, we recommend updating to that version if you are below, or creating an issue in GitHub, updating the wiki if the current information is missing, outdated or lacking.
To get started with Nexus, we recommend reading the following in chronological:
- Installation & Preparing Nexus
- Designing Commands
- Command Interceptors
- Additional Features (Subcommand Router, Option Validation)
- Context Menus
- Command Synchronization
You may want to read a specific part of handling command and middleware responses:
You can also read about additional features of Nexus:
- Subcommand Routing
- Option Validation
- Express Way (shard management)
- Inheritance
- Feather Pagination
- Nexus.R
You can read about synchronizing commands to Discord:
For more additional performance:
Additional configurations: