Sunar

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

PropTypeDefault
guildIds
string[]
-
cooldown
CooldownResolvable
-

Last updated on

On this page

GitHubEdit on Github ↗