ContextMenu
Context menu commands are available directly in the right-click context menu for users or messages. These commands are convenient for quick actions without needing to type a command.
Usage
import { ContextMenu, execute } from 'sunar';
import { ApplicationCommandType } from 'discord.js';
const contextMenu = new ContextMenu({
name: 'example',
type: ApplicationCommandType.User,
});
execute(contextMenu, (interaction) => {
// handle execution
});
export { contextMenu };Implementation
The following example demonstrates how to implement a Context Menu command using Sunar:
import { ContextMenu, execute } from 'sunar';
import { ApplicationCommandType } from 'discord.js';
const contextMenu = new ContextMenu({
name: 'Show avatar',
type: ApplicationCommandType.User,
});
execute(contextMenu, (interaction) => {
const avatarURL = interaction.targetUser.displayAvatarURL({
size: 1024,
forceStatic: false,
});
interaction.reply({
content: `Avatar of user **${interaction.user.username}**`,
files: [avatarURL],
});
});
export { contextMenu };Reference
ContextMenuConfig
Prop
Type
How is this guide?
Last updated on
Button
Buttons are interactive elements users can click to trigger specific actions. They are ideal for creating interactive messages, such as confirmation prompts or menu navigation.
Modal
Modals are popup forms that can collect detailed user input. They are particularly useful for complex interactions that require multiple fields or steps.