Context menu commands are application commands that appear in the context menu when right-clicking on users or messages in Discord. They provide quick access to bot functionality without requiring slash commands.
Builder for creating context menu commands.
class ContextMenuCommandBuilder {
readonly name: string;
readonly name_localizations?: LocalizationMap;
readonly type: ContextMenuCommandType;
readonly contexts?: InteractionContextType[];
readonly default_member_permissions?: Permissions | bigint | number | null;
readonly dm_permission?: boolean;
readonly default_permission?: boolean;
readonly integration_types?: ApplicationIntegrationType[];
constructor();
setName(name: string): this;
setType(type: ContextMenuCommandType): this;
setNameLocalizations(localizations: LocalizationMap): this;
setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined): this;
setDMPermission(enabled: boolean | null | undefined): this;
setDefaultPermission(value: boolean): this;
setContexts(...contexts: InteractionContextType[]): this;
setIntegrationTypes(...integrationTypes: ApplicationIntegrationType[]): this;
toJSON(): RESTPostAPIContextMenuApplicationCommandsJSONBody;
}type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User;
enum ApplicationCommandType {
ChatInput = 1,
User = 2,
Message = 3
}enum InteractionContextType {
Guild = 0,
BotDM = 1,
PrivateChannel = 2
}enum ApplicationIntegrationType {
GuildInstall = 0,
UserInstall = 1
}type Permissions = bigint;interface LocalizationMap {
[locale: string]: string;
}import { ContextMenuCommandBuilder, ApplicationCommandType } from "@discordjs/builders";
const userInfoCommand = new ContextMenuCommandBuilder()
.setName('User Info')
.setType(ApplicationCommandType.User);const pinMessageCommand = new ContextMenuCommandBuilder()
.setName('Pin Message')
.setType(ApplicationCommandType.Message);const moderateUserCommand = new ContextMenuCommandBuilder()
.setName('Moderate User')
.setType(ApplicationCommandType.User)
.setDefaultMemberPermissions('0x0000000000000004'); // KICK_MEMBERS permissionconst translateCommand = new ContextMenuCommandBuilder()
.setName('Translate')
.setType(ApplicationCommandType.Message)
.setNameLocalizations({
'es-ES': 'Traducir',
'fr': 'Traduire',
'de': 'Übersetzen',
'ja': '翻訳する'
});const dmOnlyCommand = new ContextMenuCommandBuilder()
.setName('Private Action')
.setType(ApplicationCommandType.User)
.setDMPermission(true)
.setContexts(InteractionContextType.BotDM, InteractionContextType.PrivateChannel);const guildOnlyCommand = new ContextMenuCommandBuilder()
.setName('Server Action')
.setType(ApplicationCommandType.Message)
.setDMPermission(false)
.setContexts(InteractionContextType.Guild);const userInstallCommand = new ContextMenuCommandBuilder()
.setName('Personal Tool')
.setType(ApplicationCommandType.User)
.setIntegrationTypes(
ApplicationIntegrationType.UserInstall,
ApplicationIntegrationType.GuildInstall
);const advancedCommand = new ContextMenuCommandBuilder()
.setName('Advanced Moderation')
.setType(ApplicationCommandType.User)
.setNameLocalizations({
'es-ES': 'Moderación Avanzada',
'fr': 'Modération Avancée'
})
.setDefaultMemberPermissions('0x0000000000000006') // KICK_MEMBERS | BAN_MEMBERS
.setDMPermission(false)
.setContexts(InteractionContextType.Guild)
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall);// User context menu commands
const userCommands = [
new ContextMenuCommandBuilder()
.setName('View Avatar')
.setType(ApplicationCommandType.User),
new ContextMenuCommandBuilder()
.setName('Send Message')
.setType(ApplicationCommandType.User)
.setDMPermission(true),
new ContextMenuCommandBuilder()
.setName('Add Friend')
.setType(ApplicationCommandType.User)
.setIntegrationTypes(ApplicationIntegrationType.UserInstall)
];
// Message context menu commands
const messageCommands = [
new ContextMenuCommandBuilder()
.setName('Quote Message')
.setType(ApplicationCommandType.Message),
new ContextMenuCommandBuilder()
.setName('Report Message')
.setType(ApplicationCommandType.Message)
.setDMPermission(false),
new ContextMenuCommandBuilder()
.setName('Translate Message')
.setType(ApplicationCommandType.Message)
.setNameLocalizations({
'es-ES': 'Traducir Mensaje',
'fr': 'Traduire le Message'
})
];// Support for deprecated default_permission (still functional but deprecated)
const legacyCommand = new ContextMenuCommandBuilder()
.setName('Legacy Command')
.setType(ApplicationCommandType.User)
.setDefaultPermission(false); // Deprecated: use setDefaultMemberPermissions insteadDiscord enforces these limits on context menu commands:
^[\w-]{1,32}$ (letters, numbers, underscores, hyphens)