@zygout/eris 0.0.0-stage → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +108 -2
  3. package/esm.mjs +72 -0
  4. package/index.d.ts +4407 -0
  5. package/index.js +75 -0
  6. package/lib/Client.js +4708 -0
  7. package/lib/Constants.d.ts +990 -0
  8. package/lib/Constants.js +1163 -0
  9. package/lib/command/Command.js +552 -0
  10. package/lib/command/CommandClient.js +460 -0
  11. package/lib/errors/DiscordHTTPError.js +63 -0
  12. package/lib/errors/DiscordRESTError.js +77 -0
  13. package/lib/gateway/Shard.js +3029 -0
  14. package/lib/gateway/ShardManager.js +164 -0
  15. package/lib/rest/Endpoints.js +172 -0
  16. package/lib/rest/RequestHandler.js +459 -0
  17. package/lib/structures/ApplicationCommand.js +125 -0
  18. package/lib/structures/AutoModerationRule.js +143 -0
  19. package/lib/structures/AutocompleteInteraction.js +80 -0
  20. package/lib/structures/Base.js +81 -0
  21. package/lib/structures/CategoryChannel.js +77 -0
  22. package/lib/structures/Channel.js +98 -0
  23. package/lib/structures/CommandInteraction.js +473 -0
  24. package/lib/structures/ComponentInteraction.js +538 -0
  25. package/lib/structures/DMChannel.js +278 -0
  26. package/lib/structures/Entitlement.js +77 -0
  27. package/lib/structures/ExtendedUser.js +46 -0
  28. package/lib/structures/ForumChannel.js +24 -0
  29. package/lib/structures/GroupChannel.js +106 -0
  30. package/lib/structures/Guild.js +1677 -0
  31. package/lib/structures/GuildAuditLogEntry.js +190 -0
  32. package/lib/structures/GuildChannel.js +128 -0
  33. package/lib/structures/GuildIntegration.js +99 -0
  34. package/lib/structures/GuildPreview.js +97 -0
  35. package/lib/structures/GuildScheduledEvent.js +176 -0
  36. package/lib/structures/GuildTemplate.js +76 -0
  37. package/lib/structures/GuildTextableChannel.js +260 -0
  38. package/lib/structures/Interaction.js +133 -0
  39. package/lib/structures/Invite.js +143 -0
  40. package/lib/structures/Lobby.js +108 -0
  41. package/lib/structures/LobbyMember.js +59 -0
  42. package/lib/structures/MediaChannel.js +216 -0
  43. package/lib/structures/Member.js +371 -0
  44. package/lib/structures/Message.js +708 -0
  45. package/lib/structures/ModalSubmitInteraction.js +478 -0
  46. package/lib/structures/NewsChannel.js +34 -0
  47. package/lib/structures/NewsThreadChannel.js +12 -0
  48. package/lib/structures/Permission.js +80 -0
  49. package/lib/structures/PermissionOverwrite.js +32 -0
  50. package/lib/structures/PingInteraction.js +39 -0
  51. package/lib/structures/PrivateThreadChannel.js +25 -0
  52. package/lib/structures/PublicThreadChannel.js +26 -0
  53. package/lib/structures/Role.js +163 -0
  54. package/lib/structures/SKU.js +80 -0
  55. package/lib/structures/SoundboardSound.js +79 -0
  56. package/lib/structures/StageChannel.js +59 -0
  57. package/lib/structures/StageInstance.js +55 -0
  58. package/lib/structures/Subscription.js +69 -0
  59. package/lib/structures/TextChannel.js +202 -0
  60. package/lib/structures/ThreadChannel.js +143 -0
  61. package/lib/structures/ThreadMember.js +59 -0
  62. package/lib/structures/UnavailableGuild.js +26 -0
  63. package/lib/structures/UnknownInteraction.js +502 -0
  64. package/lib/structures/User.js +296 -0
  65. package/lib/structures/VoiceChannel.js +166 -0
  66. package/lib/structures/VoiceState.js +84 -0
  67. package/lib/util/BrowserWebSocket.js +76 -0
  68. package/lib/util/Bucket.js +89 -0
  69. package/lib/util/Collection.js +202 -0
  70. package/lib/util/MultipartData.js +70 -0
  71. package/lib/util/Opus.js +33 -0
  72. package/lib/util/SequentialBucket.js +83 -0
  73. package/lib/util/emitDeprecation.js +26 -0
  74. package/lib/voice/Piper.js +300 -0
  75. package/lib/voice/SharedStream.js +238 -0
  76. package/lib/voice/VoiceConnection.js +1440 -0
  77. package/lib/voice/VoiceConnectionManager.js +151 -0
  78. package/lib/voice/VoiceDataStream.js +22 -0
  79. package/lib/voice/streams/BaseTransformer.js +40 -0
  80. package/lib/voice/streams/DCAOpusTransformer.js +78 -0
  81. package/lib/voice/streams/FFmpegDuplex.js +192 -0
  82. package/lib/voice/streams/FFmpegOggTransformer.js +35 -0
  83. package/lib/voice/streams/FFmpegPCMTransformer.js +26 -0
  84. package/lib/voice/streams/OggOpusTransformer.js +108 -0
  85. package/lib/voice/streams/PCMOpusTransformer.js +61 -0
  86. package/lib/voice/streams/VolumeTransformer.js +50 -0
  87. package/lib/voice/streams/WebmOpusTransformer.js +258 -0
  88. package/package.json +81 -4
@@ -0,0 +1,473 @@
1
+ "use strict";
2
+
3
+ const Interaction = require("./Interaction");
4
+ const Member = require("./Member");
5
+ const User = require("./User");
6
+ const Role = require("./Role");
7
+ const Channel = require("./Channel");
8
+ const Message = require("./Message");
9
+ const Collection = require("../util/Collection");
10
+
11
+ const { InteractionResponseTypes } = require("../Constants");
12
+
13
+ /**
14
+ * Represents an application command interaction. See Interaction for more properties.
15
+ * @extends Interaction
16
+ * @prop {Permission?} appPermissions The permissions the app or bot has within the channel the interaction was sent from
17
+ * @prop {DMChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached
18
+ * @prop {Object} data The data attached to the interaction
19
+ * @prop {String} data.id The ID of the Application Command
20
+ * @prop {String} data.name The command name
21
+ * @prop {Array<Object>?} data.options The run Application Command options
22
+ * @prop {String} data.options[].name The name of the Application Command option
23
+ * @prop {Array<Object>?} data.options[].options The run Application Command options (Mutually exclusive with value)
24
+ * @prop {Number} data.options[].type Command option type, 1-10
25
+ * @prop {(String | Number | Boolean)?} data.options[].value The value of the run Application Command (Mutually exclusive with options)
26
+ * @prop {String?} data.target_id The ID the of user or message targetted by a context menu command
27
+ * @prop {Number} data.type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types)
28
+ * @prop {Object?} data.resolved converted users + roles + channels
29
+ * @prop {Collection<Channel>?} data.resolved.channels converted channels
30
+ * @prop {Collection<Member>?} data.resolved.members converted members
31
+ * @prop {Collection<Role>?} data.resolved.roles converted roles
32
+ * @prop {Collection<User>?} data.resolved.users converted users
33
+ * @prop {String?} guildID The ID of the guild in which the interaction was created
34
+ * @prop {Member?} member The member who triggered the interaction (This is only sent when the interaction is invoked within a guild)
35
+ * @prop {User?} user The user who triggered the interaction (This is only sent when the interaction is invoked within a dm)
36
+ */
37
+ class CommandInteraction extends Interaction {
38
+ constructor(data, client) {
39
+ super(data, client);
40
+
41
+ this.channel = this._client.getChannel(data.channel_id) || {
42
+ id: data.channel_id,
43
+ };
44
+
45
+ this.data = JSON.parse(JSON.stringify(data.data));
46
+
47
+ if (data.data.resolved !== undefined) {
48
+ // Users
49
+ if (data.data.resolved.users !== undefined) {
50
+ const usermap = new Collection(User);
51
+ Object.entries(data.data.resolved.users).forEach(([id, user]) => {
52
+ usermap.set(id, this._client.users.update(user, client));
53
+ });
54
+ this.data.resolved.users = usermap;
55
+ }
56
+ // Members
57
+ if (data.data.resolved.members !== undefined) {
58
+ const membermap = new Collection(Member);
59
+ Object.entries(data.data.resolved.members).forEach(([id, member]) => {
60
+ member.id = id;
61
+ member.user = { id };
62
+ membermap.set(id, this._resolveMember(member, data));
63
+ });
64
+ this.data.resolved.members = membermap;
65
+ }
66
+ // Roles
67
+ if (data.data.resolved.roles !== undefined) {
68
+ const rolemap = new Collection(Role);
69
+ Object.entries(data.data.resolved.roles).forEach(([id, role]) => {
70
+ rolemap.set(id, new Role(role, this._resolveGuild(data)));
71
+ });
72
+ this.data.resolved.roles = rolemap;
73
+ }
74
+ // Channels
75
+ if (data.data.resolved.channels !== undefined) {
76
+ const channelmap = new Collection(Channel);
77
+ Object.entries(data.data.resolved.channels).forEach(([id, channel]) => {
78
+ channelmap.set(id, new Channel(channel, this._client));
79
+ });
80
+ this.data.resolved.channels = channelmap;
81
+ }
82
+ // Messages
83
+ if (data.data.resolved.messages !== undefined) {
84
+ const messagemap = new Collection(Message);
85
+ Object.entries(data.data.resolved.messages).forEach(([id, message]) => {
86
+ messagemap.set(id, new Message(message, this._client));
87
+ });
88
+ this.data.resolved.messages = messagemap;
89
+ }
90
+ }
91
+
92
+ if (data.guild_id !== undefined) {
93
+ this.guildID = data.guild_id;
94
+ }
95
+
96
+ if (data.member !== undefined) {
97
+ this.member = this._resolveMember(data.member, data);
98
+ }
99
+
100
+ if (data.user !== undefined) {
101
+ this.user = this._client.users.update(data.user, client);
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Acknowledges the interaction with a defer response
107
+ * Note: You can **not** use more than 1 initial interaction response per interaction
108
+ * @arg {Number} [flags] 64 for Ephemeral
109
+ * @returns {Promise}
110
+ */
111
+ async acknowledge(flags) {
112
+ return this.defer(flags);
113
+ }
114
+
115
+ /**
116
+ * Respond to the interaction with a followup message
117
+ * @arg {String | Object} content A string or object. If an object is passed:
118
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
119
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
120
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
121
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
122
+ * @arg {Array<Object>} [content.attachments] An array of attachment objects with the filename and description
123
+ * @arg {String} [content.attachments[].description] The description of the file
124
+ * @arg {String} [content.attachments[].filename] The name of the file
125
+ * @arg {Number} content.attachments[].id The index of the file
126
+ * @arg {Array<Object>} [content.components] An array of component objects
127
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
128
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
129
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
130
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
131
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
132
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
133
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
134
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
135
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
136
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
137
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
138
+ * @arg {String} [content.components[].options[].description] The description for this option
139
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
140
+ * @arg {String} content.components[].options[].label The label for this option
141
+ * @arg {Number | String} content.components[].options[].value The value for this option
142
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
143
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
144
+ * @arg {Number} [content.components[].style] The style of the component (type 2 only) - If 1-4, `custom_id` is required; if 5, `url` is required; if 6, `sku_id` is required
145
+ * @arg {Number} content.components[].type The type of component - If 1, it is a collection and a `components` array (nested) is required; if 2, it is a button; if 3, it is a string select; if 4, it is a text input; if 5, it is a user select; if 6, it is a role select; if 7, it is a mentionable select; if 8, it is a channel select; if 9, it is a section; if 10, it is a text display; if 11, it is a thumbnail; if 12, it is a media gallery; if 13, it is a file; if 14, it is a separator; if 17, it is a container; if 18, it is a label (modals only); if 19, it is a file upload (modals only); if 21, it is a radio group (modals only); if 22, it is a checkbox group (modals only); if 23, it is a checkbox (modals only)
146
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
147
+ * @arg {String} [content.content] A content string
148
+ * @arg {Object} [content.embed] [DEPRECATED] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
149
+ * @arg {Array<Object>} [options.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
150
+ * @arg {Number} [content.flags] 64 for Ephemeral
151
+ * @arg {Object} [content.poll] A poll object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/poll#poll-object) for object structure
152
+ * @arg {Boolean} [content.tts] Set the message TTS flag
153
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
154
+ * @arg {Buffer} file.file A buffer containing file data
155
+ * @arg {String} file.name What to name the file
156
+ * @returns {Promise<Message?>}
157
+ */
158
+ async createFollowup(content, file) {
159
+ if (this.acknowledged === false) {
160
+ throw new Error("createFollowup cannot be used to acknowledge an interaction, please use acknowledge, createMessage, or defer first.");
161
+ }
162
+ if (content !== undefined) {
163
+ if (typeof content !== "object" || content === null) {
164
+ content = {
165
+ content: "" + content,
166
+ };
167
+ } else if (content.content !== undefined && typeof content.content !== "string") {
168
+ content.content = "" + content.content;
169
+ }
170
+ }
171
+ if (file) {
172
+ content.file = file;
173
+ }
174
+ return this._client.executeWebhook.call(this._client, this.applicationID, this.token, Object.assign({ wait: true }, content));
175
+ }
176
+
177
+ /**
178
+ * Acknowledges the interaction with a message. If already acknowledged runs createFollowup
179
+ * @arg {String | Object} content A string or object. If an object is passed:
180
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
181
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
182
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
183
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
184
+ * @arg {Array<Object>} [content.attachments] An array of attachment objects with the filename and description
185
+ * @arg {String} [content.attachments[].description] The description of the file
186
+ * @arg {String} [content.attachments[].filename] The name of the file
187
+ * @arg {Number} content.attachments[].id The index of the file
188
+ * @arg {Array<Object>} [content.components] An array of component objects
189
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
190
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
191
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
192
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
193
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
194
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
195
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
196
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
197
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
198
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
199
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
200
+ * @arg {String} [content.components[].options[].description] The description for this option
201
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
202
+ * @arg {String} content.components[].options[].label The label for this option
203
+ * @arg {Number | String} content.components[].options[].value The value for this option
204
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
205
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
206
+ * @arg {Number} [content.components[].style] The style of the component (type 2 only) - If 1-4, `custom_id` is required; if 5, `url` is required; if 6, `sku_id` is required
207
+ * @arg {Number} content.components[].type The type of component - If 1, it is a collection and a `components` array (nested) is required; if 2, it is a button; if 3, it is a string select; if 4, it is a text input; if 5, it is a user select; if 6, it is a role select; if 7, it is a mentionable select; if 8, it is a channel select; if 9, it is a section; if 10, it is a text display; if 11, it is a thumbnail; if 12, it is a media gallery; if 13, it is a file; if 14, it is a separator; if 17, it is a container; if 18, it is a label (modals only); if 19, it is a file upload (modals only); if 21, it is a radio group (modals only); if 22, it is a checkbox group (modals only); if 23, it is a checkbox (modals only)
208
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
209
+ * @arg {String} [content.content] A content string
210
+ * @arg {Object} [content.embed] [DEPRECATED] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
211
+ * @arg {Array<Object>} [content.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
212
+ * @arg {Number} [content.flags] 64 for Ephemeral
213
+ * @arg {Object} [content.poll] A poll object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/poll#poll-object) for object structure
214
+ * @arg {Boolean} [content.tts] Set the message TTS flag
215
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
216
+ * @arg {Buffer} file.file A buffer containing file data
217
+ * @arg {String} file.name What to name the file
218
+ * @returns {Promise}
219
+ */
220
+ async createMessage(content, file) {
221
+ if (this.acknowledged === true) {
222
+ return this.createFollowup(content, file);
223
+ }
224
+ if (content !== undefined) {
225
+ if (typeof content !== "object" || content === null) {
226
+ content = {
227
+ content: "" + content,
228
+ };
229
+ } else if (content.content !== undefined && typeof content.content !== "string") {
230
+ content.content = "" + content.content;
231
+ }
232
+ if (content.content !== undefined || content.embeds || content.allowedMentions) {
233
+ content.allowed_mentions = this._client._formatAllowedMentions(content.allowedMentions);
234
+ }
235
+ }
236
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
237
+ type: InteractionResponseTypes.CHANNEL_MESSAGE_WITH_SOURCE,
238
+ data: content,
239
+ }, file).then(() => this.update());
240
+ }
241
+
242
+ /**
243
+ * Responds to an interaction with a modal
244
+ * @arg {Object} content An object
245
+ * @arg {String} [content.title] The title for the modal, max 45 characters
246
+ * @arg {String} [content.custom_id] The custom identifier for the modal
247
+ * @arg {Array<Object>} [content.components] An array of component objects
248
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
249
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
250
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
251
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
252
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
253
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
254
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
255
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
256
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
257
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
258
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
259
+ * @arg {String} [content.components[].options[].description] The description for this option
260
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
261
+ * @arg {String} content.components[].options[].label The label for this option
262
+ * @arg {Number | String} content.components[].options[].value The value for this option
263
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
264
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
265
+ * @arg {Number} [content.components[].style] The style of the component (type 2 only) - If 1-4, `custom_id` is required; if 5, `url` is required; if 6, `sku_id` is required
266
+ * @arg {Number} content.components[].type The type of component - If 1, it is a collection and a `components` array (nested) is required; if 2, it is a button; if 3, it is a string select; if 4, it is a text input; if 5, it is a user select; if 6, it is a role select; if 7, it is a mentionable select; if 8, it is a channel select; if 9, it is a section; if 10, it is a text display; if 11, it is a thumbnail; if 12, it is a media gallery; if 13, it is a file; if 14, it is a separator; if 17, it is a container; if 18, it is a label (modals only); if 19, it is a file upload (modals only); if 21, it is a radio group (modals only); if 22, it is a checkbox group (modals only); if 23, it is a checkbox (modals only)
267
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
268
+ * @returns {Promise}
269
+ */
270
+ async createModal(content) {
271
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
272
+ type: InteractionResponseTypes.MODAL,
273
+ data: content,
274
+ }).then(() => this.update());
275
+ }
276
+
277
+ /**
278
+ * Acknowledges the interaction with a defer response
279
+ * Note: You can **not** use more than 1 initial interaction response per interaction
280
+ * @arg {Number} [flags] 64 for Ephemeral
281
+ * @returns {Promise}
282
+ */
283
+ async defer(flags) {
284
+ if (this.acknowledged === true) {
285
+ throw new Error("You have already acknowledged this interaction.");
286
+ }
287
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
288
+ type: InteractionResponseTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE,
289
+ data: {
290
+ flags: flags || 0,
291
+ },
292
+ }).then(() => this.update());
293
+ }
294
+
295
+ /**
296
+ * Delete a message
297
+ * @arg {String} messageID the id of the message to delete, or "@original" for the original response
298
+ * @returns {Promise}
299
+ */
300
+ async deleteMessage(messageID) {
301
+ if (this.acknowledged === false) {
302
+ throw new Error("deleteMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, or defer first.");
303
+ }
304
+ return this._client.deleteWebhookMessage.call(this._client, this.applicationID, this.token, messageID);
305
+ }
306
+
307
+ /**
308
+ * Delete the Original message
309
+ * Warning: Will error with ephemeral messages
310
+ * @returns {Promise}
311
+ */
312
+ async deleteOriginalMessage() {
313
+ if (this.acknowledged === false) {
314
+ throw new Error("deleteOriginalMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, or defer first.");
315
+ }
316
+ return this._client.deleteWebhookMessage.call(this._client, this.applicationID, this.token, "@original");
317
+ }
318
+
319
+ /**
320
+ * Edit a message
321
+ * @arg {String} messageID the id of the message to edit, or "@original" for the original response
322
+ * @arg {Object} content Interaction message edit options
323
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
324
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
325
+ * @arg {Boolean} [content.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
326
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
327
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
328
+ * @arg {Array<Object>} [content.attachments] An array of attachment objects that will be appended to the message, including new files. Only the provided files will be appended
329
+ * @arg {String} [content.attachments[].description] The description of the file
330
+ * @arg {String} [content.attachments[].filename] The name of the file. This is not required if you are attaching a new file
331
+ * @arg {Number | String} content.attachments[].id The ID of the file. If you are attaching a new file, this would be the index of the file
332
+ * @arg {Array<Object>} [content.components] An array of component objects
333
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
334
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
335
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
336
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
337
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
338
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
339
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
340
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
341
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
342
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
343
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
344
+ * @arg {String} [content.components[].options[].description] The description for this option
345
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
346
+ * @arg {String} content.components[].options[].label The label for this option
347
+ * @arg {Number | String} content.components[].options[].value The value for this option
348
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
349
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
350
+ * @arg {Number} [content.components[].style] The style of the component (type 2 only) - If 1-4, `custom_id` is required; if 5, `url` is required; if 6, `sku_id` is required
351
+ * @arg {Number} content.components[].type The type of component - If 1, it is a collection and a `components` array (nested) is required; if 2, it is a button; if 3, it is a string select; if 4, it is a text input; if 5, it is a user select; if 6, it is a role select; if 7, it is a mentionable select; if 8, it is a channel select; if 9, it is a section; if 10, it is a text display; if 11, it is a thumbnail; if 12, it is a media gallery; if 13, it is a file; if 14, it is a separator; if 17, it is a container; if 18, it is a label (modals only); if 19, it is a file upload (modals only); if 21, it is a radio group (modals only); if 22, it is a checkbox group (modals only); if 23, it is a checkbox (modals only)
352
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
353
+ * @arg {String} [content.content] A content string
354
+ * @arg {Object} [content.embed] [DEPRECATED] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
355
+ * @arg {Array<Object>} [content.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
356
+ * @arg {Object} [content.poll] A poll object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/poll#poll-object) for object structure. Polls can only be added when editing a deferred interaction response
357
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
358
+ * @arg {Buffer} file.file A buffer containing file data
359
+ * @arg {String} file.name What to name the file
360
+ * @returns {Promise<Message>}
361
+ */
362
+ async editMessage(messageID, content, file) {
363
+ if (this.acknowledged === false) {
364
+ throw new Error("editMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, or defer first.");
365
+ }
366
+ if (content !== undefined) {
367
+ if (typeof content !== "object" || content === null) {
368
+ content = {
369
+ content: "" + content,
370
+ };
371
+ } else if (content.content !== undefined && typeof content.content !== "string") {
372
+ content.content = "" + content.content;
373
+ }
374
+ }
375
+ if (file) {
376
+ content.file = file;
377
+ }
378
+ return this._client.editWebhookMessage.call(this._client, this.applicationID, this.token, messageID, content);
379
+ }
380
+
381
+ /**
382
+ * Edit the Original response message
383
+ * @arg {Object} content Interaction message edit options
384
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
385
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
386
+ * @arg {Boolean} [content.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
387
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
388
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
389
+ * @arg {Array<Object>} [content.attachments] An array of attachment objects that will be appended to the message, including new files. Only the provided files will be appended
390
+ * @arg {String} [content.attachments[].description] The description of the file
391
+ * @arg {String} [content.attachments[].filename] The name of the file. This is not required if you are attaching a new file
392
+ * @arg {Number | String} content.attachments[].id The ID of the file. If you are attaching a new file, this would be the index of the file
393
+ * @arg {Array<Object>} [content.components] An array of component objects
394
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
395
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
396
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
397
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
398
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
399
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
400
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
401
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
402
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
403
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
404
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
405
+ * @arg {String} [content.components[].options[].description] The description for this option
406
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
407
+ * @arg {String} content.components[].options[].label The label for this option
408
+ * @arg {Number | String} content.components[].options[].value The value for this option
409
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
410
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
411
+ * @arg {Number} [content.components[].style] The style of the component (type 2 only) - If 1-4, `custom_id` is required; if 5, `url` is required; if 6, `sku_id` is required
412
+ * @arg {Number} content.components[].type The type of component - If 1, it is a collection and a `components` array (nested) is required; if 2, it is a button; if 3, it is a string select; if 4, it is a text input; if 5, it is a user select; if 6, it is a role select; if 7, it is a mentionable select; if 8, it is a channel select; if 9, it is a section; if 10, it is a text display; if 11, it is a thumbnail; if 12, it is a media gallery; if 13, it is a file; if 14, it is a separator; if 17, it is a container; if 18, it is a label (modals only); if 19, it is a file upload (modals only); if 21, it is a radio group (modals only); if 22, it is a checkbox group (modals only); if 23, it is a checkbox (modals only)
413
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
414
+ * @arg {String} [content.content] A content string
415
+ * @arg {Object} [content.embed] [DEPRECATED] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
416
+ * @arg {Array<Object>} [content.embeds] An array of embed objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
417
+ * @arg {Object} [content.poll] A poll object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/poll#poll-object) for object structure. Polls can only be added when editing a deferred interaction response
418
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
419
+ * @arg {Buffer} file.file A buffer containing file data
420
+ * @arg {String} file.name What to name the file
421
+ * @returns {Promise<Message>}
422
+ */
423
+ async editOriginalMessage(content, file) {
424
+ if (this.acknowledged === false) {
425
+ throw new Error("editOriginalMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, or defer first.");
426
+ }
427
+ if (content !== undefined) {
428
+ if (typeof content !== "object" || content === null) {
429
+ content = {
430
+ content: "" + content,
431
+ };
432
+ } else if (content.content !== undefined && typeof content.content !== "string") {
433
+ content.content = "" + content.content;
434
+ }
435
+ }
436
+ if (file) {
437
+ content.file = file;
438
+ }
439
+ return this._client.editWebhookMessage.call(this._client, this.applicationID, this.token, "@original", content);
440
+ }
441
+
442
+ /**
443
+ * Get the Original response message
444
+ * Warning: Will error with ephemeral messages
445
+ * @returns {Promise<Message>}
446
+ */
447
+ async getOriginalMessage() {
448
+ if (this.acknowledged === false) {
449
+ throw new Error("getOriginalMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, or defer first.");
450
+ }
451
+ return this._client.getWebhookMessage.call(this._client, this.applicationID, this.token, "@original");
452
+ }
453
+
454
+ /**
455
+ * Responds to the interaction by launching the Activity associated with the app
456
+ * Note: Only available for apps with Activities enabled. You can **not** use more than 1 initial interaction response per interaction
457
+ * @returns {Promise<Object>} Resolves with the interaction callback response. The ID of the launched activity instance is in `interaction.activityInstanceID` and `resource.activityInstance.id`
458
+ */
459
+ async launchActivity() {
460
+ if (this.acknowledged === true) {
461
+ throw new Error("You have already acknowledged this interaction.");
462
+ }
463
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
464
+ type: InteractionResponseTypes.LAUNCH_ACTIVITY,
465
+ withResponse: true,
466
+ }).then((response) => {
467
+ this.update();
468
+ return response;
469
+ });
470
+ }
471
+ }
472
+
473
+ module.exports = CommandInteraction;