or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

assertions.mdcomponents-v2.mdcontext-menu-commands.mdembeds.mdindex.mdmessage-components.mdmodals.mdselect-menus.mdslash-commands.mdutilities.md
tile.json

context-menu-commands.mddocs/

Context Menu Commands

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.

ContextMenuCommandBuilder

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;
}

Types

Context Menu Command Types

type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User;

enum ApplicationCommandType {
  ChatInput = 1,
  User = 2,
  Message = 3
}

Interaction Context Types

enum InteractionContextType {
  Guild = 0,
  BotDM = 1,
  PrivateChannel = 2
}

Application Integration Types

enum ApplicationIntegrationType {
  GuildInstall = 0,
  UserInstall = 1
}

Permissions

type Permissions = bigint;

Localization Map

interface LocalizationMap {
  [locale: string]: string;
}

Usage Examples

User Context Menu Command

import { ContextMenuCommandBuilder, ApplicationCommandType } from "@discordjs/builders";

const userInfoCommand = new ContextMenuCommandBuilder()
  .setName('User Info')
  .setType(ApplicationCommandType.User);

Message Context Menu Command

const pinMessageCommand = new ContextMenuCommandBuilder()
  .setName('Pin Message')
  .setType(ApplicationCommandType.Message);

Context Menu Command with Permissions

const moderateUserCommand = new ContextMenuCommandBuilder()
  .setName('Moderate User')
  .setType(ApplicationCommandType.User)
  .setDefaultMemberPermissions('0x0000000000000004'); // KICK_MEMBERS permission

Context Menu Command with Localization

const translateCommand = new ContextMenuCommandBuilder()
  .setName('Translate')
  .setType(ApplicationCommandType.Message)
  .setNameLocalizations({
    'es-ES': 'Traducir',
    'fr': 'Traduire',
    'de': 'Übersetzen',
    'ja': '翻訳する'
  });

Context Menu Command for DMs

const dmOnlyCommand = new ContextMenuCommandBuilder()
  .setName('Private Action')
  .setType(ApplicationCommandType.User)
  .setDMPermission(true)
  .setContexts(InteractionContextType.BotDM, InteractionContextType.PrivateChannel);

Guild-Only Context Menu Command

const guildOnlyCommand = new ContextMenuCommandBuilder()
  .setName('Server Action')
  .setType(ApplicationCommandType.Message)
  .setDMPermission(false)
  .setContexts(InteractionContextType.Guild);

Context Menu Command with Integration Types

const userInstallCommand = new ContextMenuCommandBuilder()
  .setName('Personal Tool')
  .setType(ApplicationCommandType.User)
  .setIntegrationTypes(
    ApplicationIntegrationType.UserInstall,
    ApplicationIntegrationType.GuildInstall
  );

Advanced Context Menu Command

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);

Collection of Context Menu Commands

// 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'
    })
];

Deprecated API Support

// Support for deprecated default_permission (still functional but deprecated)
const legacyCommand = new ContextMenuCommandBuilder()
  .setName('Legacy Command')
  .setType(ApplicationCommandType.User)
  .setDefaultPermission(false); // Deprecated: use setDefaultMemberPermissions instead

Common Use Cases

User Context Menu Commands

  • View Profile: Display detailed user information
  • Send DM: Initiate private message
  • Add Friend: Send friend request
  • Report User: Report for violations
  • Moderate User: Kick, ban, timeout actions
  • View Avatar: Display user's avatar
  • Check Permissions: Show user's server permissions

Message Context Menu Commands

  • Pin/Unpin: Toggle message pin status
  • Quote: Quote message in current channel
  • Translate: Translate message content
  • Report: Report message for violations
  • Save: Save message to personal collection
  • React: Quick reaction with emoji
  • Copy Link: Copy message link to clipboard

Context Menu Command Limits

Discord enforces these limits on context menu commands:

  • Name: Maximum 32 characters
  • Name: Must match regex ^[\w-]{1,32}$ (letters, numbers, underscores, hyphens)
  • Per Application: Maximum 5 user commands and 5 message commands per application
  • Localization: Support for all Discord-supported locales

Best Practices

  1. Clear Naming: Use descriptive names that clearly indicate the action
  2. Appropriate Permissions: Set proper permissions for moderation commands
  3. Context Awareness: Consider where the command will be used (guild vs DM)
  4. Localization: Provide translations for international users
  5. Integration Types: Choose appropriate installation contexts
  6. Graceful Errors: Handle cases where the action cannot be performed