-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
command-with-decorators.ts
59 lines (54 loc) · 1.69 KB
/
command-with-decorators.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { ApplyOptions, RequiresClientPermissions, RequiresDMContext, RequiresGuildContext } from '@sapphire/decorators';
import { send } from '@sapphire/plugin-editable-commands';
import { Subcommand } from '@sapphire/plugin-subcommands';
import { EmbedBuilder, PermissionFlagsBits, type Message } from 'discord.js';
@ApplyOptions<Subcommand.Options>({
aliases: ['cwd'],
description: 'A basic command with some subcommands',
subcommands: [
{
name: 'add',
messageRun: 'messageAdd'
},
{
name: 'create',
messageRun: 'messageAdd'
},
{
name: 'remove',
messageRun: 'messageRemove'
},
{
name: 'reset',
messageRun: 'messageReset'
},
{
name: 'show',
messageRun: 'messageShow',
default: true
}
]
})
export class UserCommand extends Subcommand {
// Anyone should be able to view the result, but not modify
public async messageShow(message: Message) {
return send(message, 'Showing!');
}
@RequiresClientPermissions([PermissionFlagsBits.EmbedLinks]) // This sub-command requires the bot to have EMBED_LINKS permission because it sends a EmbedBuilder
public async messageAdd(message: Message) {
const embed = new EmbedBuilder() //
.setColor('#3986E4')
.setDescription('Added!')
.setTitle('Configuration Log')
.setTimestamp();
return send(message, { embeds: [embed] });
}
@RequiresGuildContext((message: Message) => send(message, 'This sub-command can only be used in servers'))
public async messageRemove(message: Message) {
return send(message, 'Removing!');
}
@RequiresDMContext((message: Message) => send(message, 'This sub-command can only be used in DMs'))
public async messageReset(message: Message) {
return send(message, 'Resetting!');
}
}