-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
226 lines (203 loc) · 8.97 KB
/
Copy pathindex.d.ts
File metadata and controls
226 lines (203 loc) · 8.97 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import type {
APIUser,
APIInteractionGuildMember,
Locale,
APIChatInputApplicationCommandInteraction,
APIInteractionDataResolvedGuildMember,
APIRole,
APIInteractionDataResolvedChannel,
APIMessage,
APIAttachment,
APIChatInputApplicationCommandInteractionData,
APIApplicationCommandInteractionDataOption,
APIApplicationCommandInteractionDataBasicOption,
APIApplicationCommandOption,
APIContextMenuInteractionData,
APIContextMenuInteraction,
RESTPutAPIApplicationCommandsJSONBody
} from "discord-api-types/v10"
/**
* A wrapper around the Discord Chat Input Interaction
*/
export class ChatInputCommand {
/** The user who initiated this command */
public readonly author: APIUser
/** The member object of the user if this command was initiated in a guild */
public readonly member: APIInteractionGuildMember | null
/** The id of the guild this command was initiated in if any */
public readonly guild_id: string | null
/** The channel this command was initiated in */
public readonly channel: APIChatInputApplicationCommandInteraction["channel"]
/** The language the user initiating this command has set on their Discord client */
public readonly locale: Locale
/** The preferred language of the guild this command was initiated in if any */
public readonly guild_locale: Locale | null
/** The data inputted to the command if any such as options and their resolutions */
public readonly data: ChatInputCommandData
/** The Discord auto generated id of the command/webhook */
public readonly id: string
/** The id of the app this command is for */
public readonly application_id: string
/** The token for this command/webhook to respond/update responses */
public readonly token: string
/** The permissions the app or bot has within the channel the command was initiated in */
public readonly app_permissions: string
/**
* @param interaction The Chat Input Interaction received from Discord
*/
public constructor(interaction: APIChatInputApplicationCommandInteraction)
}
/**
* A wrapper around the Chat Input Interaction's options and their resolutions
* using Maps for fast K, V fetching instead of iterating over the raw Object from the
* API to find options and their resolutions
*/
export class ChatInputCommandData {
/** Resolved users from the supplied options */
public readonly users: Map<string, APIUser>
/** Resolved members from the supplied options */
public readonly members: Map<string, APIInteractionDataResolvedGuildMember>
/** Resolved roles from the supllied options */
public readonly roles: Map<string, APIRole>
/** Resolved channels from the supplied options */
public readonly channels: Map<string, APIInteractionDataResolvedChannel>
/** Resolved attachments from the supplied options */
public readonly attachments: Map<string, APIAttachment>
/** The options the user sent. For options that needed resolutions, the command options wrap id strings */
public readonly options: Map<string, CommandOption>
/**
* @param data The data for the Chat Input Interaction received from Discord
*/
public constructor(data: APIChatInputApplicationCommandInteractionData)
}
/**
* A wrapper around any of the option types Discord could send from a user
* Supports sub commands and their subsequent options
*/
export class CommandOption {
/** If a sub command, the options for said sub command. Empty Map otherwise */
public readonly options: Map<string, CommandOption>
/** The backing value this CommandOption represents or null if a sub command or was optional and not supplied. Use the as* methods to assert types */
public readonly value: unknown
/**
* @param data The data for this option received from Discord
*/
public constructor(data: APIApplicationCommandInteractionDataOption | APIApplicationCommandInteractionDataBasicOption)
/** Assert this command option to be a string or null if the option was optional and not supplied */
public asString(): string | null
/** Assert this command option to be a number or null if the option was optional and not supplied */
public asNumber(): number | null
/** Assert this command option to be a boolean or null if the option was optional and not supplied */
public asBoolean(): boolean | null
}
/**
* A wrapper around commands issued from the Discord context menu
*/
export class ContextMenuCommand {
/** The user who initiated this command */
public readonly author: APIUser
/** The member object of the user if this command was initiated in a guild */
public readonly member: APIInteractionGuildMember | null
/** The id of the guild this command was initiated in if any */
public readonly guild_id: string | null
/** The channel this command was initiated in */
public readonly channel: APIContextMenuInteraction["channel"]
/** The language the user initiating this command has set on their Discord client */
public readonly locale: Locale
/** The preferred language of the guild this command was initiated in if any */
public readonly guild_locale: Locale | null
/** The resolved data for the target of this command */
public readonly data: ContextMenuCommandData
/** The id of the target this command was issued for */
public readonly target: string
/** The Discord auto generated id of the command/webhook */
public readonly id: string
/** The id of the app this command is for */
public readonly application_id: string
/** The token for this command/webhook to respond/update responses */
public readonly token: string
/** The permissions the app or bot has within the channel the command was initiated in */
public readonly app_permissions: string
/**
* @param interaction The Context Menu Interaction from Discord
*/
public constructor(interaction: APIContextMenuInteraction)
}
/**
* A wrapper around the Context Menu command and its resolutions
* using Maps for fast K, V fetching instead of iterating over the raw Object from the
* API to find options and their resolutions
*/
export class ContextMenuCommandData {
/** The id of the target this command was issued for */
public readonly target_id: string
/** Resolved users from the context menu interaction */
public readonly users: Map<string, APIUser>
/** Resolved members from the context menu interaction */
public readonly members: Map<string, APIInteractionDataResolvedGuildMember>
/** Resolved messages from the context menu interaction */
public readonly messages: Map<string, APIMessage>
/**
* @param data The data for the Context Menu Interaction from Discord
*/
public constructor(data: APIContextMenuInteractionData)
}
/**
* A manager to store command info and their callback along with a centralized
* way to handle incoming commands and handle the errors that might arise from
* their execution
*/
export class CommandManager<Params extends Array<unknown>> {
/** Commands assigned to this manager */
public readonly commands: Map<string, Command<Params>>
/** Categories from assigned commands. Managed automatically */
public readonly categories: Map<string, Array<string>>
public paramGetter: (command: APIChatInputApplicationCommandInteraction) => Params
public errorHandler?: (command: APIChatInputApplicationCommandInteraction, error: unknown) => unknown
/**
* @param paramGetter Function to get the types and values for every or specific commands. Typically for all
* @param errorHandler Function to handle errors from command execution or from the reply function
*/
public constructor(
paramGetter: (command: APIChatInputApplicationCommandInteraction) => Params,
errorHandler?: (command: APIChatInputApplicationCommandInteraction, error: unknown) => unknown
)
/**
* Assign commands to this manager
* @param properties An Array of commands
*/
public assign(properties: Array<Command<Params>>): void
/**
* Remove commands from this manager
* @param commands An array of command names
*/
public remove(commands: Array<string>): void
/**
* Returns JSON representations of the commands this manager contains that can be sent to Discord directly.
* If you have localizations, you will need to add them yourself.
*/
public toJSON(): RESTPutAPIApplicationCommandsJSONBody
/**
* Handler for incoming chat input command interactions
* @param command The interaction from Discord
* @param replyFn An optional function to reply to Discord
* @returns A boolean of if the command was handled or not
*/
public handle(command: APIChatInputApplicationCommandInteraction, replyFn?: () => Promise<unknown> | unknown): boolean
/** Actual handler for the async part of the handler. `handle` isn't async because Discord wants a reply ASAP. */
private _handle(command: APIChatInputApplicationCommandInteraction, replyFn?: () => Promise<unknown> | unknown): Promise<void>
}
export type Command<Params extends Array<unknown>> = {
name: string
type?: 1 | 2 | 3
integration_types?: Array<number>
contexts?: Array<number>
options?: Array<APIApplicationCommandOption>
description: string
category: string
guild_ids?: Array<string>
examples?: Array<string>
order?: number
default_member_permissions?: string | null
process(...args: Params): unknown
}