Sunar

Slash

Slash commands are one of the primary ways users interact with bots. They provide a structured way for users to issue commands directly within the chat interface.

Usage

import { Slash, execute } from 'sunar';
 
const slash = new Slash({
	name: 'example',
	description: 'example description',
});
 
execute(slash, (interaction) => {
	// handle execution
});
 
export { slash };

Implementation

The following example demonstrates how to implement a Slash command using Sunar:

import { Slash, execute } from 'sunar';
import { ApplicationCommandOptionType } from 'discord.js';
 
const slash = new Slash({
	name: 'avatar',
	description: 'Show user avatar',
	options: [
		{
			name: 'target',
			description: 'Target user',
			type: ApplicationCommandOptionType.User,
		},
	],
});
 
execute(slash, (interaction) => {
	const user = interaction.options.getUser('target') ?? interaction.user;
 
	const avatarURL = user.displayAvatarURL({
		size: 1024,
		forceStatic: false,
	});
 
	interaction.reply({
		content: `Avatar of user **${interaction.user.username}**`,
		files: [avatarURL],
	});
});
 
export { slash };

Reference

SlashConfig

PropTypeDefault
guildIds
string[]
-
cooldown
CooldownResolvable
-

Last updated on

On this page

GitHubEdit on Github ↗