@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,478 @@
1
+ "use strict";
2
+
3
+ const Interaction = require("./Interaction");
4
+ const Channel = require("./Channel");
5
+ const Collection = require("../util/Collection");
6
+ const Member = require("./Member");
7
+ const Role = require("./Role");
8
+ const User = require("./User");
9
+ const { InteractionResponseTypes } = require("../Constants");
10
+
11
+ /**
12
+ * Represents a modal submit interaction. See Interaction for more properties
13
+ * @extends Interaction
14
+ * @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
15
+ * @prop {Object} data The data attached to the interaction
16
+ * @prop {String} data.custom_id The ID of the Modal
17
+ * @prop {Array<Object>} data.components The values submitted by the user. Each entry is either an action row (type 1) containing a text input (legacy modals), a text display (type 10), or a label (type 18) containing the submitted `component` (text input, select menu, file upload, radio group, checkbox group or checkbox). See [the official Discord API documentation entry](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-component-interaction-response-structures) for object structure
18
+ * @prop {Object?} data.resolved The resolved entities of the selected options (select menus and file uploads)
19
+ * @prop {Object?} data.resolved.attachments The uploaded attachments (file uploads), keyed by attachment ID
20
+ * @prop {Collection<Channel>?} data.resolved.channels The selected channels
21
+ * @prop {Collection<Member>?} data.resolved.members The selected members
22
+ * @prop {Collection<Role>?} data.resolved.roles The selected roles
23
+ * @prop {Collection<User>?} data.resolved.users The selected users
24
+ * @prop {String?} guildID The ID of the guild in which the interaction was created
25
+ * @prop {Member?} member The member who triggered the interaction (This is only sent when the interaction is invoked within a guild)
26
+ * @prop {User?} user The user who triggered the interaction (This is only sent when the interaction is invoked within a dm)
27
+ */
28
+ class ModalSubmitInteraction extends Interaction {
29
+ constructor(data, client) {
30
+ super(data, client);
31
+
32
+ this.channel = this._client.getChannel(data.channel_id) || {
33
+ id: data.channel_id,
34
+ };
35
+
36
+ this.data = JSON.parse(JSON.stringify(data.data));
37
+
38
+ if (data.data.resolved !== undefined) {
39
+ if (data.data.resolved.users !== undefined) {
40
+ const usermap = new Collection(User);
41
+ Object.entries(data.data.resolved.users).forEach(([id, user]) => {
42
+ usermap.set(id, this._client.users.update(user, client));
43
+ });
44
+ this.data.resolved.users = usermap;
45
+ }
46
+
47
+ if (data.data.resolved.members !== undefined) {
48
+ const membermap = new Collection(Member);
49
+ Object.entries(data.data.resolved.members).forEach(([id, member]) => {
50
+ member.id = id;
51
+ member.user = { id };
52
+ membermap.set(id, this._resolveMember(member, data));
53
+ });
54
+ this.data.resolved.members = membermap;
55
+ }
56
+
57
+ if (data.data.resolved.roles !== undefined) {
58
+ const rolemap = new Collection(Role);
59
+ Object.entries(data.data.resolved.roles).forEach(([id, role]) => {
60
+ rolemap.set(id, new Role(role, this._resolveGuild(data)));
61
+ });
62
+ this.data.resolved.roles = rolemap;
63
+ }
64
+
65
+ if (data.data.resolved.channels !== undefined) {
66
+ const channelmap = new Collection(Channel);
67
+ Object.entries(data.data.resolved.channels).forEach(([id, channel]) => {
68
+ channelmap.set(id, new Channel(channel, this._client));
69
+ });
70
+ this.data.resolved.channels = channelmap;
71
+ }
72
+ }
73
+
74
+ if (data.guild_id !== undefined) {
75
+ this.guildID = data.guild_id;
76
+ }
77
+
78
+ if (data.member !== undefined) {
79
+ this.member = this._resolveMember(data.member, data);
80
+ }
81
+
82
+ if (data.user !== undefined) {
83
+ this.user = this._client.users.update(data.user, client);
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Acknowledges the interaction with a defer message update response
89
+ * @returns {Promise}
90
+ */
91
+ async acknowledge() {
92
+ return this.deferUpdate();
93
+ }
94
+
95
+ /**
96
+ * Respond to the interaction with a followup message
97
+ * @arg {String | Object} content A string or object. If an object is passed:
98
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
99
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
100
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
101
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
102
+ * @arg {Array<Object>} [content.components] An array of component objects
103
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
104
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
105
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
106
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
107
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
108
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
109
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
110
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
111
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
112
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
113
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
114
+ * @arg {String} [content.components[].options[].description] The description for this option
115
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
116
+ * @arg {String} content.components[].options[].label The label for this option
117
+ * @arg {Number | String} content.components[].options[].value The value for this option
118
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
119
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
120
+ * @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
121
+ * @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)
122
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
123
+ * @arg {String} [content.content] A content string
124
+ * @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
125
+ * @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
126
+ * @arg {Number} [content.flags] 64 for Ephemeral
127
+ * @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
128
+ * @arg {Boolean} [content.tts] Set the message TTS flag
129
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
130
+ * @arg {Buffer} file.file A buffer containing file data
131
+ * @arg {String} file.name What to name the file
132
+ * @returns {Promise<Message?>}
133
+ */
134
+ async createFollowup(content, file) {
135
+ if (this.acknowledged === false) {
136
+ throw new Error("createFollowup cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
137
+ }
138
+ if (content !== undefined) {
139
+ if (typeof content !== "object" || content === null) {
140
+ content = {
141
+ content: "" + content,
142
+ };
143
+ } else if (content.content !== undefined && typeof content.content !== "string") {
144
+ content.content = "" + content.content;
145
+ }
146
+ }
147
+ if (file) {
148
+ content.file = file;
149
+ }
150
+ return this._client.executeWebhook.call(this._client, this.applicationID, this.token, Object.assign({ wait: true }, content));
151
+ }
152
+
153
+ /**
154
+ * Acknowledges the interaction with a message. If already acknowledged runs createFollowup
155
+ * @arg {String | Object} content A string or object. If an object is passed:
156
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
157
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
158
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
159
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
160
+ * @arg {Array<Object>} [content.components] An array of component objects
161
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
162
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
163
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
164
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
165
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
166
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
167
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
168
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
169
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
170
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
171
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
172
+ * @arg {String} [content.components[].options[].description] The description for this option
173
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
174
+ * @arg {String} content.components[].options[].label The label for this option
175
+ * @arg {Number | String} content.components[].options[].value The value for this option
176
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
177
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
178
+ * @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
179
+ * @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)
180
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
181
+ * @arg {String} [content.content] A content string
182
+ * @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
183
+ * @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
184
+ * @arg {Number} [content.flags] 64 for Ephemeral
185
+ * @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
186
+ * @arg {Boolean} [content.tts] Set the message TTS flag
187
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
188
+ * @arg {Buffer} file.file A buffer containing file data
189
+ * @arg {String} file.name What to name the file
190
+ * @returns {Promise}
191
+ */
192
+ async createMessage(content, file) {
193
+ if (this.acknowledged === true) {
194
+ return this.createFollowup(content, file);
195
+ }
196
+ if (content !== undefined) {
197
+ if (typeof content !== "object" || content === null) {
198
+ content = {
199
+ content: "" + content,
200
+ };
201
+ } else if (content.content !== undefined && typeof content.content !== "string") {
202
+ content.content = "" + content.content;
203
+ }
204
+ if (content.content !== undefined || content.embeds || content.allowedMentions) {
205
+ content.allowed_mentions = this._client._formatAllowedMentions(content.allowedMentions);
206
+ }
207
+ }
208
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
209
+ type: InteractionResponseTypes.CHANNEL_MESSAGE_WITH_SOURCE,
210
+ data: content,
211
+ }, file).then(() => this.update());
212
+ }
213
+
214
+ /**
215
+ * Acknowledges the interaction with a defer response
216
+ * Note: You can **not** use more than 1 initial interaction response per interaction
217
+ * @arg {Number} [flags] 64 for Ephemeral
218
+ * @returns {Promise}
219
+ */
220
+ async defer(flags) {
221
+ if (this.acknowledged === true) {
222
+ throw new Error("You have already acknowledged this interaction.");
223
+ }
224
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
225
+ type: InteractionResponseTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE,
226
+ data: {
227
+ flags: flags || 0,
228
+ },
229
+ }).then(() => this.update());
230
+ }
231
+
232
+ /**
233
+ * Acknowledges the interaction with a defer message update response
234
+ * Note: You can **not** use more than 1 initial interaction response per interaction
235
+ * @returns {Promise}
236
+ */
237
+ async deferUpdate() {
238
+ if (this.acknowledged === true) {
239
+ throw new Error("You have already acknowledged this interaction.");
240
+ }
241
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
242
+ type: InteractionResponseTypes.DEFERRED_UPDATE_MESSAGE,
243
+ }).then(() => this.update());
244
+ }
245
+
246
+ /**
247
+ * Delete a message
248
+ * @arg {String} messageID the id of the message to delete, or "@original" for the original response
249
+ * @returns {Promise}
250
+ */
251
+ async deleteMessage(messageID) {
252
+ if (this.acknowledged === false) {
253
+ throw new Error("deleteMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
254
+ }
255
+ return this._client.deleteWebhookMessage.call(this._client, this.applicationID, this.token, messageID);
256
+ }
257
+
258
+ /**
259
+ * Delete the parent message
260
+ * Warning: Will error with ephemeral messages
261
+ * @returns {Promise}
262
+ */
263
+ async deleteOriginalMessage() {
264
+ if (this.acknowledged === false) {
265
+ throw new Error("deleteOriginalMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
266
+ }
267
+ return this._client.deleteWebhookMessage.call(this._client, this.applicationID, this.token, "@original");
268
+ }
269
+
270
+ /**
271
+ * Edit a message
272
+ * @arg {String} messageID the id of the message to edit, or "@original" for the original response
273
+ * @arg {Object} content Interaction message edit options
274
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
275
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
276
+ * @arg {Boolean} [content.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
277
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
278
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
279
+ * @arg {Array<Object>} [content.components] An array of component objects
280
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
281
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
282
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
283
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
284
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
285
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
286
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
287
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
288
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
289
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
290
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
291
+ * @arg {String} [content.components[].options[].description] The description for this option
292
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
293
+ * @arg {String} content.components[].options[].label The label for this option
294
+ * @arg {Number | String} content.components[].options[].value The value for this option
295
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
296
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
297
+ * @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
298
+ * @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)
299
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
300
+ * @arg {String} [content.content] A content string
301
+ * @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
302
+ * @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
303
+ * @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
304
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
305
+ * @arg {Buffer} file.file A buffer containing file data
306
+ * @arg {String} file.name What to name the file
307
+ * @returns {Promise<Message>}
308
+ */
309
+ async editMessage(messageID, content, file) {
310
+ if (this.acknowledged === false) {
311
+ throw new Error("editMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
312
+ }
313
+ if (content !== undefined) {
314
+ if (typeof content !== "object" || content === null) {
315
+ content = {
316
+ content: "" + content,
317
+ };
318
+ } else if (content.content !== undefined && typeof content.content !== "string") {
319
+ content.content = "" + content.content;
320
+ }
321
+ }
322
+ if (file) {
323
+ content.file = file;
324
+ }
325
+ return this._client.editWebhookMessage.call(this._client, this.applicationID, this.token, messageID, content);
326
+ }
327
+
328
+ /**
329
+ * Edit the parent message
330
+ * @arg {Object} content Interaction message edit options
331
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
332
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
333
+ * @arg {Boolean} [content.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
334
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
335
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
336
+ * @arg {Array<Object>} [content.components] An array of component objects
337
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
338
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
339
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
340
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
341
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
342
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
343
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
344
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
345
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
346
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
347
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
348
+ * @arg {String} [content.components[].options[].description] The description for this option
349
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
350
+ * @arg {String} content.components[].options[].label The label for this option
351
+ * @arg {Number | String} content.components[].options[].value The value for this option
352
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
353
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
354
+ * @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
355
+ * @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)
356
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
357
+ * @arg {String} [content.content] A content string
358
+ * @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
359
+ * @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
360
+ * @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
361
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
362
+ * @arg {Buffer} file.file A buffer containing file data
363
+ * @arg {String} file.name What to name the file
364
+ * @returns {Promise<Message>}
365
+ */
366
+ async editOriginalMessage(content, file) {
367
+ if (this.acknowledged === false) {
368
+ throw new Error("editOriginalMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
369
+ }
370
+ if (content !== undefined) {
371
+ if (typeof content !== "object" || content === null) {
372
+ content = {
373
+ content: "" + content,
374
+ };
375
+ } else if (content.content !== undefined && typeof content.content !== "string") {
376
+ content.content = "" + content.content;
377
+ }
378
+ }
379
+ if (file) {
380
+ content.file = file;
381
+ }
382
+ return this._client.editWebhookMessage.call(this._client, this.applicationID, this.token, "@original", content);
383
+ }
384
+
385
+ /**
386
+ * Acknowledges the interaction by editing the parent message. If already acknowledged runs editOriginalMessage
387
+ * Warning: Will error with ephemeral messages
388
+ * @arg {String | Object} content What to edit the message with
389
+ * @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
390
+ * @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
391
+ * @arg {Boolean} [content.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
392
+ * @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
393
+ * @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
394
+ * @arg {Array<Object>} [content.components] An array of component objects
395
+ * @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
396
+ * @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
397
+ * @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
398
+ * @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
399
+ * @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
400
+ * @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
401
+ * @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
402
+ * @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
403
+ * @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
404
+ * @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
405
+ * @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
406
+ * @arg {String} [content.components[].options[].description] The description for this option
407
+ * @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
408
+ * @arg {String} content.components[].options[].label The label for this option
409
+ * @arg {Number | String} content.components[].options[].value The value for this option
410
+ * @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
411
+ * @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
412
+ * @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
413
+ * @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)
414
+ * @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
415
+ * @arg {String} [content.content] A content string
416
+ * @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
417
+ * @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
418
+ * @arg {Boolean} [content.flags] 64 for Ephemeral
419
+ * @arg {Boolean} [content.tts] Set the message TTS flag
420
+ * @arg {Object | Array<Object>} [file] A file object (or an Array of them)
421
+ * @arg {Buffer} file.file A buffer containing file data
422
+ * @arg {String} file.name What to name the file
423
+ * @returns {Promise}
424
+ */
425
+ async editParent(content, file) {
426
+ if (this.acknowledged === true) {
427
+ return this.editOriginalMessage(content);
428
+ }
429
+ if (content !== undefined) {
430
+ if (typeof content !== "object" || content === null) {
431
+ content = {
432
+ content: "" + content,
433
+ };
434
+ } else if (content.content !== undefined && typeof content.content !== "string") {
435
+ content.content = "" + content.content;
436
+ }
437
+ if (content.content !== undefined || content.embeds || content.allowedMentions) {
438
+ content.allowed_mentions = this._client._formatAllowedMentions(content.allowedMentions);
439
+ }
440
+ }
441
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
442
+ type: InteractionResponseTypes.UPDATE_MESSAGE,
443
+ data: content,
444
+ }, file).then(() => this.update());
445
+ }
446
+
447
+ /**
448
+ * Get the parent message
449
+ * Warning: Will error with ephemeral messages
450
+ * @returns {Promise<Message>}
451
+ */
452
+ async getOriginalMessage() {
453
+ if (this.acknowledged === false) {
454
+ throw new Error("getOriginalMessage cannot be used to acknowledge an interaction, please use acknowledge, createMessage, defer, deferUpdate, or editParent first.");
455
+ }
456
+ return this._client.getWebhookMessage.call(this._client, this.applicationID, this.token, "@original");
457
+ }
458
+
459
+ /**
460
+ * Responds to the interaction by launching the Activity associated with the app
461
+ * Note: Only available for apps with Activities enabled. You can **not** use more than 1 initial interaction response per interaction
462
+ * @returns {Promise<Object>} Resolves with the interaction callback response. The ID of the launched activity instance is in `interaction.activityInstanceID` and `resource.activityInstance.id`
463
+ */
464
+ async launchActivity() {
465
+ if (this.acknowledged === true) {
466
+ throw new Error("You have already acknowledged this interaction.");
467
+ }
468
+ return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
469
+ type: InteractionResponseTypes.LAUNCH_ACTIVITY,
470
+ withResponse: true,
471
+ }).then((response) => {
472
+ this.update();
473
+ return response;
474
+ });
475
+ }
476
+ }
477
+
478
+ module.exports = ModalSubmitInteraction;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ const TextChannel = require("./TextChannel");
4
+
5
+ /**
6
+ * Represents a guild news channel. See TextChannel for more properties and methods
7
+ * @extends TextChannel
8
+ */
9
+ class NewsChannel extends TextChannel {
10
+ update(data) {
11
+ super.update(data);
12
+ }
13
+
14
+ /**
15
+ * Crosspost (publish) a message to subscribed channels
16
+ * @arg {String} messageID The ID of the message
17
+ * @returns {Promise<Message>}
18
+ */
19
+ crosspostMessage(messageID) {
20
+ return this._client.crosspostMessage.call(this._client, this.id, messageID);
21
+ }
22
+
23
+ /**
24
+ * Follow this channel in another channel. This creates a webhook in the target channel
25
+ * @arg {String} webhookChannelID The ID of the target channel
26
+ * @arg {String} [reason] The reason to be displayed in audit logs
27
+ * @returns {Object} An object containing this channel's ID and the new webhook's ID
28
+ */
29
+ follow(webhookChannelID, reason) {
30
+ return this._client.followChannel.call(this._client, this.id, webhookChannelID, reason);
31
+ }
32
+ }
33
+
34
+ module.exports = NewsChannel;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ const ThreadChannel = require("./ThreadChannel");
4
+
5
+ /**
6
+ * Represents a news thread channel. See ThreadChannel for more properties and methods
7
+ * @extends ThreadChannel
8
+ */
9
+ class NewsThreadChannel extends ThreadChannel {
10
+ }
11
+
12
+ module.exports = NewsThreadChannel;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+ const { Permissions } = require("../Constants");
5
+
6
+ /**
7
+ * Represents a calculated permissions number
8
+ * @prop {BigInt} allow The allowed permissions number
9
+ * @prop {BigInt} deny The denied permissions number
10
+ * @prop {Object} json A JSON representation of the permissions number.
11
+ * If a permission key isn't there, it is not set by this permission.
12
+ * If a permission key is false, it is denied by the permission.
13
+ * If a permission key is true, it is allowed by the permission.
14
+ * i.e.:
15
+ * {
16
+ * "readMessages": true,
17
+ * "sendMessages": true,
18
+ * "manageMessages": false
19
+ * }
20
+ * In the above example, readMessages and sendMessages are allowed permissions, and manageMessages is denied. Everything else is not explicitly set.
21
+ * [A full list of permission nodes can be found on the docs reference page](/Eris/docs/reference)
22
+ */
23
+ class Permission extends Base {
24
+ constructor(allow, deny = 0) {
25
+ super();
26
+ if (typeof allow === "object") {
27
+ this.update(allow);
28
+ } else {
29
+ this.allow = BigInt(allow);
30
+ this.deny = BigInt(deny);
31
+ }
32
+ }
33
+
34
+ update(data) {
35
+ this.allow = BigInt(data.allow);
36
+ this.deny = BigInt(data.deny || 0);
37
+ }
38
+
39
+ get json() {
40
+ if (!this._json) {
41
+ this._json = {};
42
+ for (const perm of Object.keys(Permissions)) {
43
+ if (!perm.startsWith("all")) {
44
+ if (this.allow & Permissions[perm]) {
45
+ this._json[perm] = true;
46
+ } else if (this.deny & Permissions[perm]) {
47
+ this._json[perm] = false;
48
+ }
49
+ }
50
+ }
51
+ }
52
+ return this._json;
53
+ }
54
+
55
+ /**
56
+ * Check if this permission allows a specific permission
57
+ * @arg {String | BigInt} permission The name of the permission, or bit of permissions. [A full list of permission nodes can be found on the docs reference page](/Eris/docs/reference). Pass a BigInt if you want to check multiple permissions.
58
+ * @returns {Boolean} Whether the permission allows the specified permission
59
+ */
60
+ has(permission) {
61
+ if (typeof permission === "bigint") {
62
+ return (this.allow & permission) === permission;
63
+ }
64
+ return !!(this.allow & Permissions[permission]);
65
+ }
66
+
67
+ toString() {
68
+ return `[${this.constructor.name} +${this.allow} -${this.deny}]`;
69
+ }
70
+
71
+ toJSON(props = []) {
72
+ return super.toJSON([
73
+ "allow",
74
+ "deny",
75
+ ...props,
76
+ ]);
77
+ }
78
+ }
79
+
80
+ module.exports = Permission;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ const Permission = require("./Permission");
4
+
5
+ /**
6
+ * Represents a permission overwrite
7
+ * @extends Permission
8
+ * @prop {String} id The ID of the overwrite
9
+ * @prop {Number} type The type of the overwrite, either 1 for "member" or 0 for "role"
10
+ */
11
+ class PermissionOverwrite extends Permission {
12
+ constructor(data) {
13
+ super(data.allow, data.deny);
14
+ this.id = data.id;
15
+ this.type = data.type;
16
+
17
+ this.update(data);
18
+ }
19
+
20
+ update(data) {
21
+ super.update(data);
22
+ }
23
+
24
+ toJSON(props = []) {
25
+ return super.toJSON([
26
+ "type",
27
+ ...props,
28
+ ]);
29
+ }
30
+ }
31
+
32
+ module.exports = PermissionOverwrite;