@zygout/eris 0.0.0-stage → 0.19.0

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 +80 -3
  3. package/esm.mjs +72 -0
  4. package/index.d.ts +4397 -0
  5. package/index.js +75 -0
  6. package/lib/Client.js +4683 -0
  7. package/lib/Constants.d.ts +988 -0
  8. package/lib/Constants.js +1161 -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 +82 -6
@@ -0,0 +1,538 @@
1
+ "use strict";
2
+
3
+ const Interaction = require("./Interaction");
4
+ const Collection = require("../util/Collection");
5
+ const User = require("./User");
6
+ const Role = require("./Role");
7
+ const Member = require("./Member");
8
+ const Channel = require("./Channel");
9
+ const Message = require("./Message");
10
+ const { InteractionResponseTypes } = require("../Constants");
11
+
12
+ /**
13
+ * Represents a message component interaction. See Interaction for more properties
14
+ * @extends Interaction
15
+ * @prop {Permission?} appPermissions The permissions the app or bot has within the channel the interaction was sent from
16
+ * @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
17
+ * @prop {Object} data The data attached to the interaction
18
+ * @prop {Number} data.component_type The type of Message Component
19
+ * @prop {String} data.custom_id The ID of the Message Component
20
+ * @prop {Object?} data.resolved converted users + roles + channels resolved within the interaction (Select Menus Only)
21
+ * @prop {Collection<Channel>?} data.resolved.channels resolved channels
22
+ * @prop {Collection<Member>?} data.resolved.members resolved members
23
+ * @prop {Collection<Role>?} data.resolved.roles resolved roles
24
+ * @prop {Collection<User>?} data.resolved.users resolved users
25
+ * @prop {Array<String>?} data.values The value of the run selected options (Select Menus Only)
26
+ * @prop {String?} guildID The ID of the guild in which the interaction was created
27
+ * @prop {Member?} member The member who triggered the interaction (This is only sent when the interaction is invoked within a guild)
28
+ * @prop {Message?} message The message the interaction came from
29
+ * @prop {User?} user The user who triggered the interaction (This is only sent when the interaction is invoked within a dm)
30
+ */
31
+ class ComponentInteraction extends Interaction {
32
+ constructor(data, client) {
33
+ super(data, client);
34
+
35
+ this.channel = this._client.getChannel(data.channel_id) || {
36
+ id: data.channel_id,
37
+ };
38
+
39
+ this.data = JSON.parse(JSON.stringify(data.data));
40
+
41
+ if (data.data.resolved !== undefined) {
42
+ if (data.data.resolved.users !== undefined) {
43
+ const usermap = new Collection(User);
44
+ Object.entries(data.data.resolved.users).forEach(([id, user]) => {
45
+ usermap.set(id, this._client.users.update(user, client));
46
+ });
47
+ this.data.resolved.users = usermap;
48
+ }
49
+
50
+ if (data.data.resolved.members !== undefined) {
51
+ const membermap = new Collection(Member);
52
+ Object.entries(data.data.resolved.members).forEach(([id, member]) => {
53
+ member.id = id;
54
+ member.user = { id };
55
+ membermap.set(id, this._resolveMember(member, data));
56
+ });
57
+ this.data.resolved.members = membermap;
58
+ }
59
+
60
+ if (data.data.resolved.roles !== undefined) {
61
+ const rolemap = new Collection(Role);
62
+ Object.entries(data.data.resolved.roles).forEach(([id, role]) => {
63
+ rolemap.set(id, new Role(role, this._resolveGuild(data)));
64
+ });
65
+ this.data.resolved.roles = rolemap;
66
+ }
67
+
68
+ if (data.data.resolved.channels !== undefined) {
69
+ const channelmap = new Collection(Channel);
70
+ Object.entries(data.data.resolved.channels).forEach(([id, channel]) => {
71
+ channelmap.set(id, Channel.from(channel, this._client) || new Channel(channel, this._client));
72
+ });
73
+ this.data.resolved.channels = channelmap;
74
+ }
75
+ }
76
+
77
+ if (data.guild_id !== undefined) {
78
+ this.guildID = data.guild_id;
79
+ }
80
+
81
+ if (data.member !== undefined) {
82
+ this.member = this._resolveMember(data.member, data);
83
+ }
84
+
85
+ if (data.message !== undefined) {
86
+ this.message = new Message(data.message, this._client);
87
+ }
88
+
89
+ if (data.user !== undefined) {
90
+ this.user = this._client.users.update(data.user, client);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Acknowledges the interaction with a defer message update response
96
+ * @returns {Promise}
97
+ */
98
+ async acknowledge() {
99
+ return this.deferUpdate();
100
+ }
101
+
102
+ /**
103
+ * Respond to the interaction with a followup message
104
+ * @arg {String | Object} content A string or object. If an object is passed:
105
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
106
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
107
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
108
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
109
+ * @arg {Array<Object>} [content.attachments] An array of attachment objects with the filename and description
110
+ * @arg {String} [content.attachments[].description] The description of the file
111
+ * @arg {String} [content.attachments[].filename] The name of the file
112
+ * @arg {Number} content.attachments[].id The index of the file
113
+ * @arg {Array<Object>} [content.components] An array of component objects
114
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
115
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
116
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
117
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
118
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
119
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
120
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
121
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
122
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
123
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
124
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
125
+ * @arg {String} [content.components[].options[].description] The description for this option
126
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
127
+ * @arg {String} content.components[].options[].label The label for this option
128
+ * @arg {Number | String} content.components[].options[].value The value for this option
129
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
130
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
131
+ * @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
132
+ * @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)
133
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
134
+ * @arg {String} [content.content] A content string
135
+ * @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
136
+ * @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
137
+ * @arg {Number} [content.flags] 64 for Ephemeral
138
+ * @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
139
+ * @arg {Boolean} [content.tts] Set the message TTS flag
140
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
141
+ * @arg {Buffer} file.file A buffer containing file data
142
+ * @arg {String} file.name What to name the file
143
+ * @returns {Promise<Message?>}
144
+ */
145
+ async createFollowup(content, file) {
146
+ if (this.acknowledged === false) {
147
+ throw new Error("createFollowup cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
148
+ }
149
+ if (content !== undefined) {
150
+ if (typeof content !== "object" || content === null) {
151
+ content = {
152
+ content: "" + content,
153
+ };
154
+ } else if (content.content !== undefined && typeof content.content !== "string") {
155
+ content.content = "" + content.content;
156
+ }
157
+ }
158
+ if (file) {
159
+ content.file = file;
160
+ }
161
+ return this._client.executeWebhook.call(this._client, this.applicationID, this.token, Object.assign({ wait: true }, content));
162
+ }
163
+
164
+ /**
165
+ * Acknowledges the interaction with a message. If already acknowledged runs createFollowup
166
+ * @arg {String | Object} content A string or object. If an object is passed:
167
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
168
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
169
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
170
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
171
+ * @arg {Array<Object>} [content.attachments] An array of attachment objects with the filename and description
172
+ * @arg {String} [content.attachments[].description] The description of the file
173
+ * @arg {String} [content.attachments[].filename] The name of the file
174
+ * @arg {Number} content.attachments[].id The index of the file
175
+ * @arg {Array<Object>} [content.components] An array of component objects
176
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
177
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
178
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
179
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
180
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
181
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
182
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
183
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
184
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
185
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
186
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
187
+ * @arg {String} [content.components[].options[].description] The description for this option
188
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
189
+ * @arg {String} content.components[].options[].label The label for this option
190
+ * @arg {Number | String} content.components[].options[].value The value for this option
191
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
192
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
193
+ * @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
194
+ * @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)
195
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
196
+ * @arg {String} [content.content] A content string
197
+ * @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
198
+ * @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
199
+ * @arg {Number} [content.flags] 64 for Ephemeral
200
+ * @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
201
+ * @arg {Boolean} [content.tts] Set the message TTS flag
202
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
203
+ * @arg {Buffer} file.file A buffer containing file data
204
+ * @arg {String} file.name What to name the file
205
+ * @returns {Promise}
206
+ */
207
+ async createMessage(content, file) {
208
+ if (this.acknowledged === true) {
209
+ return this.createFollowup(content, file);
210
+ }
211
+ if (content !== undefined) {
212
+ if (typeof content !== "object" || content === null) {
213
+ content = {
214
+ content: "" + content,
215
+ };
216
+ } else if (content.content !== undefined && typeof content.content !== "string") {
217
+ content.content = "" + content.content;
218
+ }
219
+ if (content.content !== undefined || content.embeds || content.allowedMentions) {
220
+ content.allowed_mentions = this._client._formatAllowedMentions(content.allowedMentions);
221
+ }
222
+ }
223
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
224
+ type: InteractionResponseTypes.CHANNEL_MESSAGE_WITH_SOURCE,
225
+ data: content,
226
+ }, file).then(() => this.update());
227
+ }
228
+
229
+ /**
230
+ * Responds to an interaction with a modal
231
+ * @arg {Object} content An object
232
+ * @arg {String} [content.title] The title for the modal, max 45 characters
233
+ * @arg {String} [content.custom_id] The custom identifier for the modal
234
+ * @arg {Array<Object>} [content.components] An array of component objects
235
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 0-4 and type 3 only)
236
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3 only)
237
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
238
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
239
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
240
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
241
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
242
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
243
+ * @arg {String} [content.components[].options[].description] The description for this option
244
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
245
+ * @arg {String} content.components[].options[].label The label for this option
246
+ * @arg {Number | String} content.components[].options[].value The value for this option
247
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3 only)
248
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
249
+ * @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
250
+ * @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)
251
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
252
+ * @returns {Promise}
253
+ */
254
+ async createModal(content) {
255
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
256
+ type: InteractionResponseTypes.MODAL,
257
+ data: content,
258
+ }).then(() => this.update());
259
+ }
260
+
261
+ /**
262
+ * Acknowledges the interaction with a defer response
263
+ * Note: You can **not** use more than 1 initial interaction response per interaction
264
+ * @arg {Number} [flags] 64 for Ephemeral
265
+ * @returns {Promise}
266
+ */
267
+ async defer(flags) {
268
+ if (this.acknowledged === true) {
269
+ throw new Error("You have already acknowledged this interaction.");
270
+ }
271
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
272
+ type: InteractionResponseTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE,
273
+ data: {
274
+ flags: flags || 0,
275
+ },
276
+ }).then(() => this.update());
277
+ }
278
+
279
+ /**
280
+ * Acknowledges the interaction with a defer message update response
281
+ * Note: You can **not** use more than 1 initial interaction response per interaction
282
+ * @returns {Promise}
283
+ */
284
+ async deferUpdate() {
285
+ if (this.acknowledged === true) {
286
+ throw new Error("You have already acknowledged this interaction.");
287
+ }
288
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
289
+ type: InteractionResponseTypes.DEFERRED_UPDATE_MESSAGE,
290
+ }).then(() => this.update());
291
+ }
292
+
293
+ /**
294
+ * Delete a message
295
+ * @arg {String} messageID the id of the message to delete, or "@original" for the original response
296
+ * @returns {Promise}
297
+ */
298
+ async deleteMessage(messageID) {
299
+ if (this.acknowledged === false) {
300
+ throw new Error("deleteMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
301
+ }
302
+ return this._client.deleteWebhookMessage.call(this._client, this.applicationID, this.token, messageID);
303
+ }
304
+
305
+ /**
306
+ * Delete the parent message
307
+ * Warning: Will error with ephemeral messages.
308
+ * @returns {Promise}
309
+ */
310
+ async deleteOriginalMessage() {
311
+ if (this.acknowledged === false) {
312
+ throw new Error("deleteOriginalMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
313
+ }
314
+ return this._client.deleteWebhookMessage.call(this._client, this.applicationID, this.token, "@original");
315
+ }
316
+
317
+ /**
318
+ * Edit a message
319
+ * @arg {String} messageID the id of the message to edit, or "@original" for the original response
320
+ * @arg {Object} content Interaction message edit options
321
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
322
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
323
+ * @arg {Boolean} [content.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
324
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
325
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
326
+ * @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
327
+ * @arg {String} [content.attachments[].description] The description of the file
328
+ * @arg {String} [content.attachments[].filename] The name of the file. This is not required if you are attaching a new file
329
+ * @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
330
+ * @arg {Array<Object>} [content.components] An array of component objects
331
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
332
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
333
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
334
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
335
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
336
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
337
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
338
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
339
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
340
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
341
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
342
+ * @arg {String} [content.components[].options[].description] The description for this option
343
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
344
+ * @arg {String} content.components[].options[].label The label for this option
345
+ * @arg {Number | String} content.components[].options[].value The value for this option
346
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
347
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
348
+ * @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
349
+ * @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)
350
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
351
+ * @arg {String} [content.content] A content string
352
+ * @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
353
+ * @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
354
+ * @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
355
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
356
+ * @arg {Buffer} file.file A buffer containing file data
357
+ * @arg {String} file.name What to name the file
358
+ * @returns {Promise<Message>}
359
+ */
360
+ async editMessage(messageID, content, file) {
361
+ if (this.acknowledged === false) {
362
+ throw new Error("editMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
363
+ }
364
+ if (content !== undefined) {
365
+ if (typeof content !== "object" || content === null) {
366
+ content = {
367
+ content: "" + content,
368
+ };
369
+ } else if (content.content !== undefined && typeof content.content !== "string") {
370
+ content.content = "" + content.content;
371
+ }
372
+ }
373
+ if (file) {
374
+ content.file = file;
375
+ }
376
+ return this._client.editWebhookMessage.call(this._client, this.applicationID, this.token, messageID, content);
377
+ }
378
+
379
+ /**
380
+ * Edit the parent message
381
+ * @arg {Object} content Interaction message edit options
382
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
383
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
384
+ * @arg {Boolean} [content.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
385
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
386
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
387
+ * @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
388
+ * @arg {String} [content.attachments[].description] The description of the file
389
+ * @arg {String} [content.attachments[].filename] The name of the file. This is not required if you are attaching a new file
390
+ * @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
391
+ * @arg {Array<Object>} [content.components] An array of component objects
392
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
393
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
394
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
395
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
396
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
397
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
398
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
399
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
400
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
401
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
402
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
403
+ * @arg {String} [content.components[].options[].description] The description for this option
404
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
405
+ * @arg {String} content.components[].options[].label The label for this option
406
+ * @arg {Number | String} content.components[].options[].value The value for this option
407
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
408
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
409
+ * @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
410
+ * @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)
411
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
412
+ * @arg {String} [content.content] A content string
413
+ * @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
414
+ * @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
415
+ * @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
416
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
417
+ * @arg {Buffer} file.file A buffer containing file data
418
+ * @arg {String} file.name What to name the file
419
+ * @returns {Promise<Message>}
420
+ */
421
+ async editOriginalMessage(content, file) {
422
+ if (this.acknowledged === false) {
423
+ throw new Error("editOriginalMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
424
+ }
425
+ if (content !== undefined) {
426
+ if (typeof content !== "object" || content === null) {
427
+ content = {
428
+ content: "" + content,
429
+ };
430
+ } else if (content.content !== undefined && typeof content.content !== "string") {
431
+ content.content = "" + content.content;
432
+ }
433
+ }
434
+ if (file) {
435
+ content.file = file;
436
+ }
437
+ return this._client.editWebhookMessage.call(this._client, this.applicationID, this.token, "@original", content);
438
+ }
439
+
440
+ /**
441
+ * Acknowledges the interaction by editing the parent message. If already acknowledged runs editOriginalMessage
442
+ * Note: You can **not** use more than 1 initial interaction response per interaction, use edit if you have already responded with a different interaction response
443
+ * Warning: Will error with ephemeral messages.
444
+ * @arg {String | Object} content What to edit the message with
445
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
446
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
447
+ * @arg {Boolean} [content.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to.
448
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
449
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
450
+ * @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
451
+ * @arg {String} [content.attachments[].description] The description of the file
452
+ * @arg {String} [content.attachments[].filename] The name of the file. This is not required if you are attaching a new file
453
+ * @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
454
+ * @arg {Array<Object>} [content.components] An array of component objects
455
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
456
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
457
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
458
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
459
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
460
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
461
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
462
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
463
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
464
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
465
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
466
+ * @arg {String} [content.components[].options[].description] The description for this option
467
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
468
+ * @arg {String} content.components[].options[].label The label for this option
469
+ * @arg {Number | String} content.components[].options[].value The value for this option
470
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
471
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
472
+ * @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
473
+ * @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)
474
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
475
+ * @arg {String} [content.content] A content string
476
+ * @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
477
+ * @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
478
+ * @arg {Number} [content.flags] 64 for Ephemeral
479
+ * @arg {Boolean} [content.tts] Set the message TTS flag
480
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
481
+ * @arg {Buffer} file.file A buffer containing file data
482
+ * @arg {String} file.name What to name the file
483
+ * @returns {Promise}
484
+ */
485
+ async editParent(content, file) {
486
+ if (this.acknowledged === true) {
487
+ return this.editOriginalMessage(content);
488
+ }
489
+ if (content !== undefined) {
490
+ if (typeof content !== "object" || content === null) {
491
+ content = {
492
+ content: "" + content,
493
+ };
494
+ } else if (content.content !== undefined && typeof content.content !== "string") {
495
+ content.content = "" + content.content;
496
+ }
497
+ if (content.content !== undefined || content.embeds || content.allowedMentions) {
498
+ content.allowed_mentions = this._client._formatAllowedMentions(content.allowedMentions);
499
+ }
500
+ }
501
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
502
+ type: InteractionResponseTypes.UPDATE_MESSAGE,
503
+ data: content,
504
+ }, file).then(() => this.update());
505
+ }
506
+
507
+ /**
508
+ * Get the parent message
509
+ * Warning: Will error with ephemeral messages
510
+ * @returns {Promise<Message>}
511
+ */
512
+ async getOriginalMessage() {
513
+ if (this.acknowledged === false) {
514
+ throw new Error("getOriginalMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
515
+ }
516
+ return this._client.getWebhookMessage.call(this._client, this.applicationID, this.token, "@original");
517
+ }
518
+
519
+ /**
520
+ * Responds to the interaction by launching the Activity associated with the app
521
+ * Note: Only available for apps with Activities enabled. You can **not** use more than 1 initial interaction response per interaction
522
+ * @returns {Promise<Object>} Resolves with the interaction callback response. The ID of the launched activity instance is in `interaction.activityInstanceID` and `resource.activityInstance.id`
523
+ */
524
+ async launchActivity() {
525
+ if (this.acknowledged === true) {
526
+ throw new Error("You have already acknowledged this interaction.");
527
+ }
528
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
529
+ type: InteractionResponseTypes.LAUNCH_ACTIVITY,
530
+ withResponse: true,
531
+ }).then((response) => {
532
+ this.update();
533
+ return response;
534
+ });
535
+ }
536
+ }
537
+
538
+ module.exports = ComponentInteraction;