Discord Context Menu Decorators
This file provides decorators for adding Discord context menu commands to controller methods in the @sodacore/core
Discord integration. These decorators attach the necessary metadata for registering message and user context menu commands using Discord.js, enabling you to handle right-click actions on messages and users within your Discord bot.
Features
- Context Menu Registration: Adds metadata to controller methods for registering Discord message and user context menu commands.
- Command Builder Integration: Uses Discord.js
ContextMenuCommandBuilder
to define command structure and type. - Unique Command Names: Ensures each context menu command is registered with a unique name.
- Method Metadata: Stores method information for later discovery and routing by the Discord module.
Usage
typescript
import { MessageContext, UserContext } from './decorator/add';
class MyDiscordController {
@MessageContext('Pin Message')
async pinMessage(context) {
// Logic to pin a message
}
@UserContext('Ban User')
async banUser(context) {
// Logic to ban a user
}
}
API
MessageContext(name: string): MethodDecorator
- name: The unique name for the message context menu command.
- Usage: Decorate a controller method to expose it as a message context menu command.
UserContext(name: string): MethodDecorator
- name: The unique name for the user context menu command.
- Usage: Decorate a controller method to expose it as a user context menu command.
How It Works
- Sets metadata on the decorated method to indicate its type (
add.messagecontext
oradd.usercontext
), unique name, and command builder. - Updates the controller's
methods
metadata array with the method's key, type, subType, and unique name. - This metadata is later used by the Discord integration to register and route context menu commands.
Notes
- These decorators are intended for use within Discord controller classes in the Sodacore framework.
- The command name provided must be unique within your bot's context menu commands.
- Only methods decorated with these decorators will be registered as context menu commands.