Context Menus
Add user and message context menu commands
Context menus appear when users right-click a user's name or a message in Discord — your custom commands show up in the Apps section of the right-click menu. Place handler files in src/context/user/ or src/context/message/ to register them.
Discord right-click context menu on a user's name showing the Apps submenu expanded, with a custom 'Info' context menu command visible in the list
For the full config reference including name localizations, server restrictions, and the ContextConfig type, see the @robojs/discordjs Context Menus reference.
Creating Context Menus
The file name becomes the command name. Spaces and capitalization in file names are preserved.
User Context Commands
User context commands receive a UserContextMenuCommandInteraction and the target User as parameters.
import type { UserContextMenuCommandInteraction, User } from 'discord.js'
export default (interaction: UserContextMenuCommandInteraction, user: User) => {
return `${user.username} joined Discord on ${user.createdAt.toDateString()}`
}export default (interaction, user) => {
return `${user.username} joined Discord on ${user.createdAt.toDateString()}`
}Message Context Commands
Message context commands receive a MessageContextMenuCommandInteraction and the target Message.
import type { MessageContextMenuCommandInteraction, Message } from 'discord.js'
export default async (interaction: MessageContextMenuCommandInteraction, message: Message) => {
await interaction.user.send(`Bookmarked: ${message.content}`)
return 'Message bookmarked!'
}export default async (interaction, message) => {
await interaction.user.send(`Bookmarked: ${message.content}`)
return 'Message bookmarked!'
}Discord right-click context menu on a message showing the Apps submenu with a custom 'Bookmark' command, alongside the standard message context options
Configuration
Export a config object using createContextConfig() to set metadata and behavior.
import { createContextConfig } from '@robojs/discordjs'
export const config = createContextConfig({
description: 'Get user information'
})import { createContextConfig } from '@robojs/discordjs'
export const config = createContextConfig({
description: 'Get user information'
})| Field | Type | Description |
|---|---|---|
description | string | Command description |
contexts | CommandContext[] | Where the command is available |
defaultMemberPermissions | PermissionResolvable | Required permissions |
integrationTypes | CommandIntegrationType[] | Install types that can use this command |
sage | false | SageOptions | Sage mode configuration |
timeout | number | Maximum execution time in milliseconds |
Context menu commands use the same Sage mode as slash commands, so returning a value from the handler replies automatically.
