Skip to main content

๐Ÿ–ฑ๏ธ Context Menu

These are your quick, right-click interactions that swoop in when users right-click a message or a user. They may not boast options, descriptions, or command stacking like slash commands, but they shine in simplicity and context awareness. Choose between "Message" and "User" to suit the situation.

Forging a Context Menu Command ๐Ÿ› ๏ธโ€‹

Carving out a context menu command is a walk in the park. Simply whip up a new file in the fitting subdirectory under /src/context, and voila - your command is born! Name your file, and hence the command, as you like - spaces and capitalized letters are A-OK here!

Here's a snapshot of what it could look like:

/src
โ””โ”€โ”€ /context
โ”œโ”€โ”€ /message
โ”‚ โ”œโ”€โ”€ Translate.js
โ”‚ โ””โ”€โ”€ Analyze Sentiment.js
โ””โ”€โ”€ /user
โ”œโ”€โ”€ Kick.js
โ””โ”€โ”€ Send Welcome Message.js

Message Command Example ๐Ÿ“ฌโ€‹

When your message command is summoned, you'll receive a MessageContextMenuCommandInteraction object and the targeted message. Pretty neat, right?

Let's say you're crafting a command to translate a message:

/src/context/message/Translate.js
import { translateMessage } from '../services/translator.js'

export default async function (interaction, message) {
const translatedContent = await translateMessage(message.content)
return `Translation: ${translatedContent}`
}

User Command Example ๐Ÿ‘คโ€‹

If you're stirring up a user command instead, you'll be served a UserContextMenuCommandInteraction object along with the selected user.

Here's a glimpse of a user command in action, giving a user the ol' kickaroo:

/src/context/user/Kick.js
export default async function (interaction, user) {
const guildMember = interaction.guild.members.resolve(user)
await guildMember.kick()
return `Yeeted ${user.username} from the server. Bye! ๐Ÿ‘‹`
}

Smooth Sailing from Here ๐ŸŒŠโ€‹

If you've already dipped your toes into slash commands, this should be a familiar beach. Your context commands get the first-class ticket with automatic registration, and Sage stays by your side, making interaction replies as cool as a cucumber. So, go ahead, craft those unique context menu commands and let your server shine! ๐ŸŒŸ

Robo.js Logo

MIT ยฉ 2024 Robo.js By WavePlay