-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Expand file tree
/
Copy pathApplicationCommand.ts
More file actions
143 lines (129 loc) · 3.88 KB
/
ApplicationCommand.ts
File metadata and controls
143 lines (129 loc) · 3.88 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { DiscordSnowflake } from '@sapphire/snowflake';
import type { APIApplicationCommand, ApplicationCommandType } from 'discord-api-types/v10';
import { Structure } from '../Structure.js';
import { kData } from '../utils/symbols.js';
import { isIdSet } from '../utils/type-guards.js';
import type { Partialize } from '../utils/types.js';
/**
* Represents any application command on Discord.
*
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
* @remarks has substructure `User` which needs to be instantiated and stored by an extending class using it
* @remarks intentionally does not export `roles` so that extending classes can resolve `Snowflake[]` to `Role[]`
*/
export class ApplicationCommand<Omitted extends keyof APIApplicationCommand | '' = ''> extends Structure<
APIApplicationCommand,
Omitted
> {
/**
* The template used for removing data from the raw data stored for each application command
*/
public static override readonly DataTemplate: Partial<APIApplicationCommand> = {};
/**
* @param data - The raw data received from the API for the application command
*/
public constructor(data: Partialize<APIApplicationCommand, Omitted>) {
super(data);
}
/**
* Unique ID of command
*
* @remarks Valid option types: ALL
*/
public get id() {
return this[kData].id;
}
/**
* Type of command
*
* @remarks Valid option types: ALL
* @defaultValue {@link ApplicationCommandType.ChatInput}
*/
public get type() {
return this[kData].type;
}
/**
* Id of the parent application
*
* @remarks Valid option types: ALL
*/
public get applicationId() {
return this[kData].application_id;
}
/**
* Guild ID of the command, if not global
*
* @remarks Valid option types: ALL
*/
public get guildId() {
return this[kData].guild_id;
}
/**
* Name of the application, 1-32 characters
*
* @remarks Valid option types: ALL
* @see {@link https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-naming}
*/
public get name() {
return this[kData].name;
}
/**
* Localization map for the `name` field.
*
* @remarks Values follow the same restrictions as `name`.
* @remarks Valid option types: ALL
* @see {@link https://discord.com/developers/docs/reference#locales}
*/
public get nameLocalizations() {
return this[kData].name_localizations;
}
/**
* Description for {@link ApplicationCommandType.ChatInput} commands, 1-100 characters.
* Empty string for {@link ApplicationCommandType.User} and {@link ApplicationCommandType.Message} commands.
*
* @remarks Valid option types: ALL
*/
public get description() {
return this[kData].description;
}
/**
* Localization map for the `description` field.
*
* @remarks Values follow the same restrictions as `description`.
* @remarks Valid option types: ALL
* @see {@link https://discord.com/developers/docs/reference#locales}
*/
public get descriptionLocalizations() {
return this[kData].description_localizations;
}
/**
* Set of permissions represented as a bit set
*
* @see {@link https://discord.com/developers/docs/topics/permissions}
*/
public get defaultMemberPermissions() {
return this[kData].default_member_permissions;
}
/**
* Whether the command is age-restricted (NSFW)
*
* @defaultValue `false`
* @see {@link https://discord.com/developers/docs/interactions/application-commands#agerestricted-commands}
*/
public get nsfw() {
return this[kData].nsfw;
}
/**
* The timestamp the command was created at
*/
public get createdTimestamp() {
return isIdSet(this.id) ? DiscordSnowflake.timestampFrom(this.id) : null;
}
/**
* The time the command was created at
*/
public get createdAt() {
const createdTimestamp = this.createdTimestamp;
return createdTimestamp ? new Date(createdTimestamp) : null;
}
}