LogoRobo.js

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

FocusThe Apps section in the right-click menu showing the custom context commandZoom100%NotesRight-click a user's name in a Discord server that has the example bot installed. Hover over or expand the Apps section. Show a custom command like 'Info' in the Apps 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.

Info.ts"Info" context menu
Bookmark.ts"Bookmark" context menu

User Context Commands

User context commands receive a UserContextMenuCommandInteraction and the target User as parameters.

src/context/user/Info.ts
import type { UserContextMenuCommandInteraction, User } from 'discord.js'

export default (interaction: UserContextMenuCommandInteraction, user: User) => {
	return `${user.username} joined Discord on ${user.createdAt.toDateString()}`
}
src/context/user/Info.js
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.

src/context/message/Bookmark.ts
import type { MessageContextMenuCommandInteraction, Message } from 'discord.js'

export default async (interaction: MessageContextMenuCommandInteraction, message: Message) => {
	await interaction.user.send(`Bookmarked: ${message.content}`)
	return 'Message bookmarked!'
}
src/context/message/Bookmark.js
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

FocusThe Apps section in the message context menu showing the Bookmark commandZoom100%NotesRight-click a message in a Discord channel with the example bot. Show the context menu with the Apps section containing the 'Bookmark' command.

Configuration

Export a config object using createContextConfig() to set metadata and behavior.

src/context/user/Info.ts
import { createContextConfig } from '@robojs/discordjs'

export const config = createContextConfig({
	description: 'Get user information'
})
src/context/user/Info.js
import { createContextConfig } from '@robojs/discordjs'

export const config = createContextConfig({
	description: 'Get user information'
})
FieldTypeDescription
descriptionstringCommand description
contextsCommandContext[]Where the command is available
defaultMemberPermissionsPermissionResolvableRequired permissions
integrationTypesCommandIntegrationType[]Install types that can use this command
sagefalse | SageOptionsSage mode configuration
timeoutnumberMaximum execution time in milliseconds

Context menu commands use the same Sage mode as slash commands, so returning a value from the handler replies automatically.

Next Steps

On this page