@zygout/eris 0.19.0 → 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.
- package/LICENSE +20 -20
- package/README.md +109 -80
- package/esm.mjs +72 -72
- package/index.d.ts +4407 -4397
- package/index.js +75 -75
- package/lib/Client.js +4708 -4683
- package/lib/Constants.d.ts +990 -988
- package/lib/Constants.js +1163 -1161
- package/lib/command/Command.js +552 -552
- package/lib/command/CommandClient.js +460 -460
- package/lib/errors/DiscordHTTPError.js +63 -63
- package/lib/errors/DiscordRESTError.js +77 -77
- package/lib/gateway/Shard.js +3029 -3029
- package/lib/gateway/ShardManager.js +164 -164
- package/lib/rest/Endpoints.js +172 -172
- package/lib/rest/RequestHandler.js +459 -459
- package/lib/structures/ApplicationCommand.js +125 -125
- package/lib/structures/AutoModerationRule.js +143 -143
- package/lib/structures/AutocompleteInteraction.js +80 -80
- package/lib/structures/Base.js +81 -81
- package/lib/structures/CategoryChannel.js +77 -77
- package/lib/structures/Channel.js +98 -98
- package/lib/structures/CommandInteraction.js +473 -473
- package/lib/structures/ComponentInteraction.js +538 -538
- package/lib/structures/DMChannel.js +278 -278
- package/lib/structures/Entitlement.js +77 -77
- package/lib/structures/ExtendedUser.js +46 -46
- package/lib/structures/ForumChannel.js +24 -24
- package/lib/structures/GroupChannel.js +106 -106
- package/lib/structures/Guild.js +1677 -1677
- package/lib/structures/GuildAuditLogEntry.js +190 -190
- package/lib/structures/GuildChannel.js +128 -128
- package/lib/structures/GuildIntegration.js +99 -99
- package/lib/structures/GuildPreview.js +97 -97
- package/lib/structures/GuildScheduledEvent.js +176 -176
- package/lib/structures/GuildTemplate.js +76 -76
- package/lib/structures/GuildTextableChannel.js +260 -260
- package/lib/structures/Interaction.js +133 -133
- package/lib/structures/Invite.js +143 -143
- package/lib/structures/Lobby.js +108 -108
- package/lib/structures/LobbyMember.js +59 -59
- package/lib/structures/MediaChannel.js +216 -216
- package/lib/structures/Member.js +371 -371
- package/lib/structures/Message.js +708 -708
- package/lib/structures/ModalSubmitInteraction.js +478 -478
- package/lib/structures/NewsChannel.js +34 -34
- package/lib/structures/NewsThreadChannel.js +12 -12
- package/lib/structures/Permission.js +80 -80
- package/lib/structures/PermissionOverwrite.js +32 -32
- package/lib/structures/PingInteraction.js +39 -39
- package/lib/structures/PrivateThreadChannel.js +25 -25
- package/lib/structures/PublicThreadChannel.js +26 -26
- package/lib/structures/Role.js +163 -163
- package/lib/structures/SKU.js +80 -80
- package/lib/structures/SoundboardSound.js +79 -79
- package/lib/structures/StageChannel.js +59 -59
- package/lib/structures/StageInstance.js +55 -55
- package/lib/structures/Subscription.js +69 -69
- package/lib/structures/TextChannel.js +202 -202
- package/lib/structures/ThreadChannel.js +143 -143
- package/lib/structures/ThreadMember.js +59 -59
- package/lib/structures/UnavailableGuild.js +26 -26
- package/lib/structures/UnknownInteraction.js +502 -502
- package/lib/structures/User.js +296 -296
- package/lib/structures/VoiceChannel.js +166 -166
- package/lib/structures/VoiceState.js +84 -84
- package/lib/util/BrowserWebSocket.js +76 -76
- package/lib/util/Bucket.js +89 -89
- package/lib/util/Collection.js +202 -202
- package/lib/util/MultipartData.js +70 -70
- package/lib/util/Opus.js +33 -33
- package/lib/util/SequentialBucket.js +83 -83
- package/lib/util/emitDeprecation.js +26 -26
- package/lib/voice/Piper.js +300 -300
- package/lib/voice/SharedStream.js +238 -238
- package/lib/voice/VoiceConnection.js +1440 -1440
- package/lib/voice/VoiceConnectionManager.js +151 -151
- package/lib/voice/VoiceDataStream.js +22 -22
- package/lib/voice/streams/BaseTransformer.js +40 -40
- package/lib/voice/streams/DCAOpusTransformer.js +78 -78
- package/lib/voice/streams/FFmpegDuplex.js +192 -192
- package/lib/voice/streams/FFmpegOggTransformer.js +35 -35
- package/lib/voice/streams/FFmpegPCMTransformer.js +26 -26
- package/lib/voice/streams/OggOpusTransformer.js +108 -108
- package/lib/voice/streams/PCMOpusTransformer.js +61 -61
- package/lib/voice/streams/VolumeTransformer.js +50 -50
- package/lib/voice/streams/WebmOpusTransformer.js +258 -258
- package/package.json +83 -82
|
@@ -1,708 +1,708 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const Base = require("./Base");
|
|
4
|
-
const Collection = require("../util/Collection");
|
|
5
|
-
const Endpoints = require("../rest/Endpoints");
|
|
6
|
-
const Member = require("./Member");
|
|
7
|
-
const { ApplicationIntegrationTypes, InteractionTypes, MessageFlags } = require("../Constants");
|
|
8
|
-
const Role = require("./Role");
|
|
9
|
-
const User = require("./User");
|
|
10
|
-
|
|
11
|
-
function parseInteractionMetadata(client, data) {
|
|
12
|
-
const owners = data.authorizing_integration_owners || {};
|
|
13
|
-
const metadata = {
|
|
14
|
-
authorizingIntegrationOwners: {
|
|
15
|
-
guildInstall: owners[ApplicationIntegrationTypes.GUILD_INSTALL],
|
|
16
|
-
userInstall: owners[ApplicationIntegrationTypes.USER_INSTALL],
|
|
17
|
-
},
|
|
18
|
-
id: data.id,
|
|
19
|
-
type: data.type,
|
|
20
|
-
user: client.users.update(data.user, client),
|
|
21
|
-
};
|
|
22
|
-
if (data.original_response_message_id !== undefined) {
|
|
23
|
-
metadata.originalResponseMessageID = data.original_response_message_id;
|
|
24
|
-
}
|
|
25
|
-
if (data.type === InteractionTypes.APPLICATION_COMMAND) {
|
|
26
|
-
if (data.target_user !== undefined) {
|
|
27
|
-
metadata.targetUser = client.users.update(data.target_user, client);
|
|
28
|
-
}
|
|
29
|
-
if (data.target_message_id !== undefined) {
|
|
30
|
-
metadata.targetMessageID = data.target_message_id;
|
|
31
|
-
}
|
|
32
|
-
} else if (data.type === InteractionTypes.MESSAGE_COMPONENT) {
|
|
33
|
-
metadata.interactedMessageID = data.interacted_message_id;
|
|
34
|
-
} else if (data.type === InteractionTypes.MODAL_SUBMIT && data.triggering_interaction_metadata) {
|
|
35
|
-
metadata.triggeringInteractionMetadata = parseInteractionMetadata(client, data.triggering_interaction_metadata);
|
|
36
|
-
}
|
|
37
|
-
return metadata;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Represents a message
|
|
42
|
-
* @prop {Object?} activity The activity specified in the message
|
|
43
|
-
* @prop {Object?} application The application of the activity in the message
|
|
44
|
-
* @prop {String?} applicationID The ID of the interaction's application
|
|
45
|
-
* @prop {Array<Object>} attachments Array of attachments
|
|
46
|
-
* @prop {User} author The message author
|
|
47
|
-
* @prop {Object} call The call associated with the message
|
|
48
|
-
* @prop {Number?} call.endedTimestamp The time when the call ended
|
|
49
|
-
* @prop {Array<String>} call.participants An array of user IDs that participated in the call
|
|
50
|
-
* @prop {DMChannel | TextChannel | NewsChannel} channel The channel the message is in. Can be partial with only the id if the channel is not cached.
|
|
51
|
-
* @prop {Array<String>} channelMentions Array of mentions channels' ids
|
|
52
|
-
* @prop {String?} cleanContent Message content with mentions replaced by names. Mentions are currently escaped, but this behavior is [DEPRECATED] and will be removed soon. Use allowed mentions, the official way of avoiding unintended mentions, when creating messages.
|
|
53
|
-
* @prop {Command?} command The Command used in the Message, if any (CommandClient only)
|
|
54
|
-
* @prop {Array<Object>} components An array of component objects
|
|
55
|
-
* @prop {String} content Message content
|
|
56
|
-
* @prop {Number} createdAt Timestamp of message creation
|
|
57
|
-
* @prop {Number?} editedTimestamp Timestamp of latest message edit
|
|
58
|
-
* @prop {Array<Object>} embeds Array of embeds
|
|
59
|
-
* @prop {Number} flags Message flags (see constants)
|
|
60
|
-
* @prop {String?} guildID The ID of the guild this message is in (undefined if in DMs)
|
|
61
|
-
* @prop {String} id The ID of the message
|
|
62
|
-
* @prop {Object?} interaction [DEPRECATED] An object containing info about the interaction the message is responding to, if applicable. Use `interactionMetadata` instead
|
|
63
|
-
* @prop {String} interaction.id The ID of the interaction
|
|
64
|
-
* @prop {Member?} interaction.member The member who invoked the interaction
|
|
65
|
-
* @prop {String} interaction.name The name of the command
|
|
66
|
-
* @prop {Number} interaction.type The type of interaction
|
|
67
|
-
* @prop {User} interaction.user The user who invoked the interaction
|
|
68
|
-
* @prop {Object?} interactionMetadata Metadata about the interaction the message was sent as a result of, if applicable
|
|
69
|
-
* @prop {Object} interactionMetadata.authorizingIntegrationOwners The IDs of the installation contexts that authorized the app (`guildInstall` and/or `userInstall`)
|
|
70
|
-
* @prop {String} interactionMetadata.id The ID of the interaction
|
|
71
|
-
* @prop {String?} interactionMetadata.interactedMessageID The ID of the message that contained the interactive component (message component interactions only)
|
|
72
|
-
* @prop {String?} interactionMetadata.originalResponseMessageID The ID of the original response message (followup messages only)
|
|
73
|
-
* @prop {String?} interactionMetadata.targetMessageID The ID of the message the command was run on (message command interactions only)
|
|
74
|
-
* @prop {User?} interactionMetadata.targetUser The user the command was run on (user command interactions only)
|
|
75
|
-
* @prop {Object?} interactionMetadata.triggeringInteractionMetadata The metadata of the interaction that opened the modal (modal submit interactions only)
|
|
76
|
-
* @prop {Number} interactionMetadata.type The type of the interaction
|
|
77
|
-
* @prop {User} interactionMetadata.user The user who triggered the interaction
|
|
78
|
-
* @prop {String} jumpLink The url used by Discord clients to jump to this message
|
|
79
|
-
* @prop {Member?} member The message author with server-specific data
|
|
80
|
-
* @prop {Boolean} mentionEveryone Whether the message mentions everyone/here or not
|
|
81
|
-
* @prop {Array<User>} mentions Array of mentioned users
|
|
82
|
-
* @prop {Object?} messageReference An object containing the reference to the original message if it is a crossposted message, reply or forwarded message
|
|
83
|
-
* @prop {String} messageReference.channelID The ID of the channel this message was crossposted from
|
|
84
|
-
* @prop {String?} messageReference.guildID The ID of the guild this message was crossposted from
|
|
85
|
-
* @prop {String?} messageReference.messageID The ID of the original message this message was crossposted from
|
|
86
|
-
* @prop {Number} messageReference.type The type of reference. Either `0` (REPLY) or `1` (FORWARDED)
|
|
87
|
-
* @prop {Array<Object>?} messageSnapshots The message associated with the messageReference
|
|
88
|
-
* @prop {String?} messageSnapshots.guildID The ID of the guild this message originated from
|
|
89
|
-
* @prop {Message} messageSnapshots.message Subset of message fields. The list of message fields subset consists of: `attachments`, `content`, `edited_timestamp`, `embeds`, `flags`, `id`, `mentions`, `roleMentions`, `timestamp` and `type`
|
|
90
|
-
* @prop {(String | Number)?} nonce The nonce used to validate that the message was sent
|
|
91
|
-
* @prop {Boolean} pinned Whether the message is pinned or not
|
|
92
|
-
* @prop {Number?} position The approximate position of the message in a thread. Can be used to estimate the relative position of the message in a thread in company with the `totalMessageSent` property of the parent thread
|
|
93
|
-
* @prop {Object?} poll A poll object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/poll#poll-object) for object structure. Note: `poll.expiry` is an int, not ISO8601 as mentioned in Discord docs
|
|
94
|
-
* @prop {String?} prefix The prefix used in the Message, if any (CommandClient only)
|
|
95
|
-
* @prop {Object} reactions An object containing the reactions on the message. Each key is a reaction emoji and each value is an object with properties `burst_colors` (Array<String>), `count` (Number), `count_details` (an object with `burst` and `normal` keys corresponding to the amount of reactions), `me` (Boolean) and `me_burst` for that specific reaction emoji.
|
|
96
|
-
* @prop {Message?} referencedMessage The message that was replied to. If undefined, message data was not received. If null, the message was deleted.
|
|
97
|
-
* @prop {Array<String>} roleMentions Array of mentioned roles' ids
|
|
98
|
-
* @prop {Object?} resolved The resolved users, members, channels and roles referenced in the message's auto-populated select menus
|
|
99
|
-
* @prop {Collection<Channel>?} resolved.channels The resolved channels
|
|
100
|
-
* @prop {Collection<Member>?} resolved.members The resolved members
|
|
101
|
-
* @prop {Collection<Role>?} resolved.roles The resolved roles
|
|
102
|
-
* @prop {Collection<User>?} resolved.users The resolved users
|
|
103
|
-
* @prop {Object?} roleSubscriptionData The data of the role subscription purchase or renewal that prompted this `ROLE_SUBSCRIPTION_PURCHASE` message
|
|
104
|
-
* @prop {Boolean} roleSubscriptionData.isRenewal Whether this notification is for a renewal rather than a new purchase
|
|
105
|
-
* @prop {String} roleSubscriptionData.roleSubscriptionListingID The ID of the SKU and listing that the user is subscribed to
|
|
106
|
-
* @prop {String} roleSubscriptionData.tierName The name of the tier that the user is subscribed to
|
|
107
|
-
* @prop {Number} roleSubscriptionData.totalMonthsSubscribed The cumulative number of months that the user has been subscribed for
|
|
108
|
-
* @prop {Object?} sharedClientTheme The custom client-side theme shared via the message
|
|
109
|
-
* @prop {Number} sharedClientTheme.baseMix The intensity of the theme colors (0-100)
|
|
110
|
-
* @prop {Number?} sharedClientTheme.baseTheme The mode of the theme. See `Constants.BaseThemeTypes`
|
|
111
|
-
* @prop {Array<String>} sharedClientTheme.colors The hexadecimal-encoded colors of the theme (max of 5)
|
|
112
|
-
* @prop {Number} sharedClientTheme.gradientAngle The direction of the theme's colors (0-360)
|
|
113
|
-
* @prop {Array<Object>?} stickers [DEPRECATED] The stickers sent with the message
|
|
114
|
-
* @prop {Array<Object>?} stickerItems The stickers sent with the message
|
|
115
|
-
* @prop {ThreadChannel?} thread The thread that was started from this message
|
|
116
|
-
* @prop {Number} timestamp Timestamp of message creation
|
|
117
|
-
* @prop {Boolean} tts Whether to play the message using TTS or not
|
|
118
|
-
* @prop {Number} type The type of the message
|
|
119
|
-
* @prop {String?} webhookID ID of the webhook that sent the message
|
|
120
|
-
*/
|
|
121
|
-
class Message extends Base {
|
|
122
|
-
constructor(data, client) {
|
|
123
|
-
super(data.id);
|
|
124
|
-
this._client = client;
|
|
125
|
-
this.type = data.type || 0;
|
|
126
|
-
this.timestamp = Date.parse(data.timestamp);
|
|
127
|
-
this.channel = this._client.getChannel(data.channel_id) || {
|
|
128
|
-
id: data.channel_id,
|
|
129
|
-
};
|
|
130
|
-
this.content = "";
|
|
131
|
-
this.reactions = {};
|
|
132
|
-
this.guildID = data.guild_id;
|
|
133
|
-
this.webhookID = data.webhook_id;
|
|
134
|
-
|
|
135
|
-
if (data.message_reference) {
|
|
136
|
-
this.messageReference = {
|
|
137
|
-
type: data.message_reference.type,
|
|
138
|
-
messageID: data.message_reference.message_id,
|
|
139
|
-
channelID: data.message_reference.channel_id,
|
|
140
|
-
guildID: data.message_reference.guild_id,
|
|
141
|
-
};
|
|
142
|
-
} else {
|
|
143
|
-
this.messageReference = null;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (data.message_snapshots && this.messageReference) {
|
|
147
|
-
this.messageSnapshots = data.message_snapshots.map((snapshot) => {
|
|
148
|
-
snapshot.message.id = this.messageReference.messageID;
|
|
149
|
-
snapshot.message.channel_id = this.messageReference.channelID;
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
guildID: this.messageReference.guildID,
|
|
153
|
-
message: new Message(snapshot.message, this._client),
|
|
154
|
-
};
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
this.flags = data.flags || 0;
|
|
159
|
-
|
|
160
|
-
if (data.author) {
|
|
161
|
-
if (data.author.discriminator !== "0000") {
|
|
162
|
-
this.author = this._client.users.update(data.author, client);
|
|
163
|
-
} else {
|
|
164
|
-
this.author = new User(data.author, client);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (data.referenced_message) {
|
|
169
|
-
const channel = this._client.getChannel(data.referenced_message.channel_id);
|
|
170
|
-
if (channel) {
|
|
171
|
-
this.referencedMessage = channel.messages.update(data.referenced_message, this._client);
|
|
172
|
-
} else {
|
|
173
|
-
this.referencedMessage = new Message(data.referenced_message, this._client);
|
|
174
|
-
}
|
|
175
|
-
} else {
|
|
176
|
-
this.referencedMessage = data.referenced_message;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (data.interaction) {
|
|
180
|
-
this.interaction = data.interaction;
|
|
181
|
-
let interactionMember;
|
|
182
|
-
const interactionUser = this._client.users.update(data.interaction.user, client);
|
|
183
|
-
if (data.interaction.member) {
|
|
184
|
-
data.interaction.member.id = data.interaction.user.id;
|
|
185
|
-
if (this.channel.guild) {
|
|
186
|
-
interactionMember = this.channel.guild.members.update(data.interaction.member, this.channel.guild);
|
|
187
|
-
} else {
|
|
188
|
-
interactionMember = data.interaction.member;
|
|
189
|
-
}
|
|
190
|
-
} else if (this.channel.guild && this.channel.guild.members.has(data.interaction.user.id)) {
|
|
191
|
-
interactionMember = this.channel.guild.members.get(data.interaction.user.id);
|
|
192
|
-
} else {
|
|
193
|
-
interactionMember = null;
|
|
194
|
-
}
|
|
195
|
-
this.interaction.user = interactionUser;
|
|
196
|
-
this.interaction.member = interactionMember;
|
|
197
|
-
} else {
|
|
198
|
-
this.interaction = null;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (data.interaction_metadata) {
|
|
202
|
-
this.interactionMetadata = parseInteractionMetadata(this._client, data.interaction_metadata);
|
|
203
|
-
} else {
|
|
204
|
-
this.interactionMetadata = null;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (data.nonce !== undefined) {
|
|
208
|
-
this.nonce = data.nonce;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (this.channel.guild) {
|
|
212
|
-
if (data.member) {
|
|
213
|
-
data.member.id = this.author.id;
|
|
214
|
-
if (data.author) {
|
|
215
|
-
data.member.user = data.author;
|
|
216
|
-
}
|
|
217
|
-
this.member = this.channel.guild.members.update(data.member, this.channel.guild);
|
|
218
|
-
} else if (this.author && this.channel.guild.members.has(this.author.id)) {
|
|
219
|
-
this.member = this.channel.guild.members.get(this.author.id);
|
|
220
|
-
} else {
|
|
221
|
-
this.member = null;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (!this.guildID) {
|
|
225
|
-
this.guildID = this.channel.guild.id;
|
|
226
|
-
}
|
|
227
|
-
} else {
|
|
228
|
-
this.member = null;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
this.update(data, client);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
update(data, client) {
|
|
235
|
-
if (data.content !== undefined) {
|
|
236
|
-
this.content = data.content || "";
|
|
237
|
-
this.mentionEveryone = !!data.mention_everyone;
|
|
238
|
-
|
|
239
|
-
this.mentions = data.mentions.map((mention) => {
|
|
240
|
-
const user = this._client.users.add(mention, client);
|
|
241
|
-
if (mention.member && this.channel.guild) {
|
|
242
|
-
mention.member.id = mention.id;
|
|
243
|
-
this.channel.guild.members.update(mention.member, this.channel.guild);
|
|
244
|
-
}
|
|
245
|
-
return user;
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
this.roleMentions = data.mention_roles;
|
|
249
|
-
}
|
|
250
|
-
if (data.poll !== undefined) {
|
|
251
|
-
this.poll = data.poll;
|
|
252
|
-
if (data.poll.expiry !== null) {
|
|
253
|
-
this.poll.expiry = Date.parse(data.poll.expiry);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
if (data.pinned !== undefined) {
|
|
257
|
-
this.pinned = !!data.pinned;
|
|
258
|
-
}
|
|
259
|
-
if (data.edited_timestamp != undefined) {
|
|
260
|
-
this.editedTimestamp = Date.parse(data.edited_timestamp);
|
|
261
|
-
}
|
|
262
|
-
if (data.tts !== undefined) {
|
|
263
|
-
this.tts = data.tts;
|
|
264
|
-
}
|
|
265
|
-
if (data.attachments !== undefined) {
|
|
266
|
-
this.attachments = data.attachments;
|
|
267
|
-
}
|
|
268
|
-
if (data.embeds !== undefined) {
|
|
269
|
-
this.embeds = data.embeds;
|
|
270
|
-
}
|
|
271
|
-
if (data.flags !== undefined) {
|
|
272
|
-
this.flags = data.flags;
|
|
273
|
-
}
|
|
274
|
-
if (data.activity !== undefined) {
|
|
275
|
-
this.activity = data.activity;
|
|
276
|
-
}
|
|
277
|
-
if (data.application !== undefined) {
|
|
278
|
-
this.application = data.application;
|
|
279
|
-
}
|
|
280
|
-
if (data.application_id !== undefined) {
|
|
281
|
-
this.applicationID = data.application_id;
|
|
282
|
-
}
|
|
283
|
-
if (data.reactions) {
|
|
284
|
-
data.reactions.forEach((reaction) => {
|
|
285
|
-
this.reactions[reaction.emoji.id ? `${reaction.emoji.name}:${reaction.emoji.id}` : reaction.emoji.name] = {
|
|
286
|
-
burst_colors: reaction.burst_colors,
|
|
287
|
-
count: reaction.count,
|
|
288
|
-
count_details: reaction.count_details,
|
|
289
|
-
me: reaction.me,
|
|
290
|
-
me_burst: reaction.me_burst,
|
|
291
|
-
};
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
if (data.stickers !== undefined) {
|
|
295
|
-
this.stickers = data.stickers;
|
|
296
|
-
}
|
|
297
|
-
if (data.sticker_items !== undefined) {
|
|
298
|
-
this.stickerItems = data.sticker_items.map((sticker) => {
|
|
299
|
-
if (sticker.user) {
|
|
300
|
-
sticker.user = this._client.users.update(sticker.user, client);
|
|
301
|
-
}
|
|
302
|
-
return sticker;
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
if (data.components !== undefined) {
|
|
306
|
-
this.components = data.components;
|
|
307
|
-
}
|
|
308
|
-
if (data.call !== undefined) {
|
|
309
|
-
this.call = {
|
|
310
|
-
endedTimestamp: Date.parse(data.call.ended_timestamp) || null,
|
|
311
|
-
participants: data.call.participants,
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
if (data.position !== undefined) {
|
|
315
|
-
this.position = data.position;
|
|
316
|
-
}
|
|
317
|
-
if (data.resolved !== undefined) {
|
|
318
|
-
const guild = this.channel.guild || this._client.guilds.get(this.guildID);
|
|
319
|
-
this.resolved = {};
|
|
320
|
-
if (data.resolved.users !== undefined) {
|
|
321
|
-
this.resolved.users = new Collection(User);
|
|
322
|
-
Object.entries(data.resolved.users).forEach(([id, user]) => {
|
|
323
|
-
this.resolved.users.set(id, this._client.users.update(user, this._client));
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
if (data.resolved.members !== undefined && guild) {
|
|
327
|
-
this.resolved.members = new Collection(Member);
|
|
328
|
-
Object.entries(data.resolved.members).forEach(([id, member]) => {
|
|
329
|
-
const memberData = Object.assign({}, member);
|
|
330
|
-
memberData.id = id;
|
|
331
|
-
memberData.user = { id };
|
|
332
|
-
this.resolved.members.set(id, guild.members.update(memberData, guild));
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
if (data.resolved.roles !== undefined) {
|
|
336
|
-
this.resolved.roles = new Collection(Role);
|
|
337
|
-
Object.entries(data.resolved.roles).forEach(([id, role]) => {
|
|
338
|
-
this.resolved.roles.set(id, new Role(role, guild || {
|
|
339
|
-
id: this.guildID,
|
|
340
|
-
}));
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
if (data.resolved.channels !== undefined) {
|
|
344
|
-
this.resolved.channels = new Collection(Channel);
|
|
345
|
-
Object.entries(data.resolved.channels).forEach(([id, channel]) => {
|
|
346
|
-
this.resolved.channels.set(id, this._client.getChannel(id) || new Channel(channel, this._client));
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
if (data.role_subscription_data !== undefined) {
|
|
351
|
-
this.roleSubscriptionData = {
|
|
352
|
-
isRenewal: data.role_subscription_data.is_renewal,
|
|
353
|
-
roleSubscriptionListingID: data.role_subscription_data.role_subscription_listing_id,
|
|
354
|
-
tierName: data.role_subscription_data.tier_name,
|
|
355
|
-
totalMonthsSubscribed: data.role_subscription_data.total_months_subscribed,
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
if (data.shared_client_theme !== undefined) {
|
|
359
|
-
this.sharedClientTheme = data.shared_client_theme && {
|
|
360
|
-
baseMix: data.shared_client_theme.base_mix,
|
|
361
|
-
baseTheme: data.shared_client_theme.base_theme,
|
|
362
|
-
colors: data.shared_client_theme.colors,
|
|
363
|
-
gradientAngle: data.shared_client_theme.gradient_angle,
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
if (data.thread !== undefined) {
|
|
367
|
-
const thread = this._client.getChannel(data.thread.id);
|
|
368
|
-
if (thread) {
|
|
369
|
-
thread.update(data.thread);
|
|
370
|
-
this.thread = thread;
|
|
371
|
-
} else {
|
|
372
|
-
this.thread = Channel.from(data.thread, this._client);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
get channelMentions() {
|
|
378
|
-
if (this._channelMentions) {
|
|
379
|
-
return this._channelMentions;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
return (this._channelMentions = ((this.content && this.content.match(/<#[0-9]+>/g)) || []).map((mention) => mention.substring(2, mention.length - 1)));
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
get cleanContent() {
|
|
386
|
-
let cleanContent = (this.content && this.content.replace(/<a?(:\w+:)[0-9]+>/g, "$1")) || "";
|
|
387
|
-
|
|
388
|
-
let authorName = this.author.username;
|
|
389
|
-
if (this.channel.guild) {
|
|
390
|
-
const member = this.channel.guild.members.get(this.author.id);
|
|
391
|
-
if (member && member.nick) {
|
|
392
|
-
authorName = member.nick;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
cleanContent = cleanContent.replace(new RegExp(`<@!?${this.author.id}>`, "g"), "@\u200b" + authorName);
|
|
396
|
-
|
|
397
|
-
if (this.mentions) {
|
|
398
|
-
this.mentions.forEach((mention) => {
|
|
399
|
-
if (this.channel.guild) {
|
|
400
|
-
const member = this.channel.guild.members.get(mention.id);
|
|
401
|
-
if (member && member.nick) {
|
|
402
|
-
cleanContent = cleanContent.replace(new RegExp(`<@!?${mention.id}>`, "g"), "@\u200b" + member.nick);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
cleanContent = cleanContent.replace(new RegExp(`<@!?${mention.id}>`, "g"), "@\u200b" + mention.username);
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (this.channel.guild && this.roleMentions) {
|
|
410
|
-
for (const roleID of this.roleMentions) {
|
|
411
|
-
const role = this.channel.guild.roles.get(roleID);
|
|
412
|
-
const roleName = role ? role.name : "deleted-role";
|
|
413
|
-
cleanContent = cleanContent.replace(new RegExp(`<@&${roleID}>`, "g"), "@\u200b" + roleName);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
this.channelMentions.forEach((id) => {
|
|
418
|
-
const channel = this._client.getChannel(id);
|
|
419
|
-
if (channel && channel.name && channel.mention) {
|
|
420
|
-
cleanContent = cleanContent.replace(channel.mention, "#" + channel.name);
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
return cleanContent.replace(/@everyone/g, "@\u200beveryone").replace(/@here/g, "@\u200bhere");
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
get jumpLink() {
|
|
428
|
-
return `${Endpoints.CLIENT_URL}${Endpoints.MESSAGE_LINK(this.guildID || "@me", this.channel.id, this.id)}`; // Messages outside of guilds (DMs) will never have a guildID property assigned
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* Add a reaction to a message
|
|
433
|
-
* @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
|
|
434
|
-
* @returns {Promise}
|
|
435
|
-
*/
|
|
436
|
-
addReaction(reaction) {
|
|
437
|
-
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
438
|
-
throw new Error("Ephemeral messages cannot have reactions");
|
|
439
|
-
}
|
|
440
|
-
return this._client.addMessageReaction.call(this._client, this.channel.id, this.id, reaction);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Create a thread with this message
|
|
445
|
-
* @arg {Object} options The thread options
|
|
446
|
-
* @arg {Number} [options.autoArchiveDuration] Duration in minutes to automatically archive the thread after recent activity, either 60, 1440, 4320 or 10080
|
|
447
|
-
* @arg {String} options.name The thread channel name
|
|
448
|
-
* @arg {Number} [options.rateLimitPerUser] The time in seconds a user has to wait before sending another message (0-21600) (does not affect bots or users with manageMessages/manageChannel permissions)
|
|
449
|
-
* @arg {String} [options.reason] The reason to be displayed in audit logs
|
|
450
|
-
* @returns {Promise<NewsThreadChannel | PublicThreadChannel>}
|
|
451
|
-
*/
|
|
452
|
-
createThreadWithMessage(options) {
|
|
453
|
-
return this._client.createThreadWithMessage.call(this._client, this.channel.id, this.id, options);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Crosspost (publish) a message to subscribed channels (NewsChannel only)
|
|
458
|
-
* @returns {Promise<Message>}
|
|
459
|
-
*/
|
|
460
|
-
crosspost() {
|
|
461
|
-
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
462
|
-
throw new Error("Ephemeral messages cannot be crossposted");
|
|
463
|
-
}
|
|
464
|
-
return this._client.crosspostMessage.call(this._client, this.channel.id, this.id);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* Delete the message
|
|
469
|
-
* @arg {String} [reason] The reason to be displayed in audit logs
|
|
470
|
-
* @returns {Promise}
|
|
471
|
-
*/
|
|
472
|
-
delete(reason) {
|
|
473
|
-
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
474
|
-
throw new Error("Ephemeral messages cannot be deleted");
|
|
475
|
-
}
|
|
476
|
-
return this._client.deleteMessage.call(this._client, this.channel.id, this.id, reason);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Delete the message as a webhook
|
|
481
|
-
* @arg {String} token The token of the webhook
|
|
482
|
-
* @returns {Promise}
|
|
483
|
-
*/
|
|
484
|
-
deleteWebhook(token) {
|
|
485
|
-
if (!this.webhookID) {
|
|
486
|
-
throw new Error("Message is not a webhook");
|
|
487
|
-
}
|
|
488
|
-
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
489
|
-
throw new Error("Ephemeral messages cannot be deleted");
|
|
490
|
-
}
|
|
491
|
-
return this._client.deleteWebhookMessage.call(this._client, this.webhookID, token, this.id);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* Edit the message
|
|
496
|
-
* @arg {String | Array | Object} content A string, array of strings, or object. If an object is passed:
|
|
497
|
-
* @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
|
|
498
|
-
* @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
|
|
499
|
-
* @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
|
|
500
|
-
* @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
|
|
501
|
-
* @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
|
|
502
|
-
* @arg {String} [content.attachments[].description] The description of the file
|
|
503
|
-
* @arg {String} [content.attachments[].filename] The name of the file. This is not required if you are attaching a new file
|
|
504
|
-
* @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
|
|
505
|
-
* @arg {Array<Object>} [content.components] An array of component objects
|
|
506
|
-
* @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
|
|
507
|
-
* @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
|
|
508
|
-
* @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
|
|
509
|
-
* @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
|
|
510
|
-
* @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
|
|
511
|
-
* @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
|
|
512
|
-
* @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
|
|
513
|
-
* @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
|
|
514
|
-
* @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
|
|
515
|
-
* @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
|
|
516
|
-
* @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
|
|
517
|
-
* @arg {String} [content.components[].options[].description] The description for this option
|
|
518
|
-
* @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
|
|
519
|
-
* @arg {String} content.components[].options[].label The label for this option
|
|
520
|
-
* @arg {Number | String} content.components[].options[].value The value for this option
|
|
521
|
-
* @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
|
|
522
|
-
* @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
|
|
523
|
-
* @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
|
|
524
|
-
* @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)
|
|
525
|
-
* @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
|
|
526
|
-
* @arg {String} [content.content] A content string
|
|
527
|
-
* @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
|
|
528
|
-
* @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
|
|
529
|
-
* @arg {Object | Array<Object>} [content.file] A file object (or an Array of them)
|
|
530
|
-
* @arg {Buffer} content.file[].file A buffer containing file data
|
|
531
|
-
* @arg {String} content.file[].name What to name the file
|
|
532
|
-
* @arg {Number} [content.flags] A number representing the flags to apply to the message. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#message-object-message-flags) for flags reference
|
|
533
|
-
* @returns {Promise<Message>}
|
|
534
|
-
*/
|
|
535
|
-
edit(content) {
|
|
536
|
-
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
537
|
-
throw new Error("Ephemeral messages cannot be edited via this method");
|
|
538
|
-
}
|
|
539
|
-
return this._client.editMessage.call(this._client, this.channel.id, this.id, content);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* Edit the message as a webhook
|
|
544
|
-
* @arg {String} token The token of the webhook
|
|
545
|
-
* @arg {Object} options Webhook message edit options
|
|
546
|
-
* @arg {Object} [options.allowedMentions] A list of mentions to allow (overrides default)
|
|
547
|
-
* @arg {Boolean} [options.allowedMentions.everyone] Whether or not to allow @everyone/@here
|
|
548
|
-
* @arg {Boolean} [options.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
|
|
549
|
-
* @arg {Boolean | Array<String>} [options.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
|
|
550
|
-
* @arg {Boolean | Array<String>} [options.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
|
|
551
|
-
* @arg {Array<Object>} [options.attachments] An array of attachment objects that will be appended to the message, including new files. Only the provided files will be appended
|
|
552
|
-
* @arg {String} [options.attachments[].description] The description of the file
|
|
553
|
-
* @arg {String} [options.attachments[].filename] The name of the file. This is not required if you are attaching a new file
|
|
554
|
-
* @arg {Number | String} options.attachments[].id The ID of the file. If you are attaching a new file, this would be the index of the file
|
|
555
|
-
* @arg {Array<Object>} [options.components] An array of component objects
|
|
556
|
-
* @arg {String} [options.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
|
|
557
|
-
* @arg {Boolean} [options.components[].disabled] Whether the component is disabled (type 2 and type 3,5,6,7,8 only)
|
|
558
|
-
* @arg {Object} [options.components[].emoji] The emoji to be displayed in the component (type 2)
|
|
559
|
-
* @arg {String} [options.components[].label] The label to be displayed in the component (type 2)
|
|
560
|
-
* @arg {Array<Object>} [options.components[].default_values] default values for the component (type 5,6,7,8 only)
|
|
561
|
-
* @arg {String} [options.components[].default_values[].id] id of a user, role, or channel
|
|
562
|
-
* @arg {String} [options.components[].default_values[].type] type of value that id represents (user, role, or channel)
|
|
563
|
-
* @arg {Number} [options.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
|
|
564
|
-
* @arg {Number} [options.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
|
|
565
|
-
* @arg {Array<Object>} [options.components[].options] The options for this component (type 3 only)
|
|
566
|
-
* @arg {Boolean} [options.components[].options[].default] Whether this option should be the default value selected
|
|
567
|
-
* @arg {String} [options.components[].options[].description] The description for this option
|
|
568
|
-
* @arg {Object} [options.components[].options[].emoji] The emoji to be displayed in this option
|
|
569
|
-
* @arg {String} options.components[].options[].label The label for this option
|
|
570
|
-
* @arg {Number | String} options.components[].options[].value The value for this option
|
|
571
|
-
* @arg {String} [options.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
|
|
572
|
-
* @arg {String} [options.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
|
|
573
|
-
* @arg {Number} [options.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
|
|
574
|
-
* @arg {Number} options.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)
|
|
575
|
-
* @arg {String} [options.components[].url] The URL that the component should open for users (type 2 style 5 only)
|
|
576
|
-
* @arg {String} [options.content] A content string
|
|
577
|
-
* @arg {Object} [options.embed] [DEPRECATED] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
|
|
578
|
-
* @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
|
|
579
|
-
* @arg {Object | Array<Object>} [options.file] A file object (or an Array of them)
|
|
580
|
-
* @arg {Buffer} options.file.file A buffer containing file data
|
|
581
|
-
* @arg {String} options.file.name What to name the file
|
|
582
|
-
* @returns {Promise<Message>}
|
|
583
|
-
*/
|
|
584
|
-
editWebhook(token, options) {
|
|
585
|
-
if (!this.webhookID) {
|
|
586
|
-
throw new Error("Message is not a webhook");
|
|
587
|
-
}
|
|
588
|
-
return this._client.editWebhookMessage.call(this._client, this.webhookID, token, this.id, options);
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
/**
|
|
592
|
-
* Get a list of users who reacted with a specific reaction
|
|
593
|
-
* @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
|
|
594
|
-
* @arg {Object} [options] Options for the request. If this is a number, it is treated as `options.limit` ([DEPRECATED] behavior)
|
|
595
|
-
* @arg {String} [options.after] Get users after this user ID
|
|
596
|
-
* @arg {Number} [options.limit=100] The maximum number of users to get
|
|
597
|
-
* @arg {Number} [options.type=0] The type of reaction (`0` for normal, `1` for burst)
|
|
598
|
-
* @arg {String} [before] [DEPRECATED] Get users before this user ID. Discord no longer supports this parameter
|
|
599
|
-
* @arg {String} [after] [DEPRECATED] Get users after this user ID
|
|
600
|
-
* @returns {Promise<Array<User>>}
|
|
601
|
-
*/
|
|
602
|
-
getReaction(reaction, options, before, after) {
|
|
603
|
-
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
604
|
-
throw new Error("Ephemeral messages cannot have reactions");
|
|
605
|
-
}
|
|
606
|
-
return this._client.getMessageReaction.call(this._client, this.channel.id, this.id, reaction, options, before, after);
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
* Pin the message
|
|
611
|
-
* @returns {Promise}
|
|
612
|
-
*/
|
|
613
|
-
pin() {
|
|
614
|
-
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
615
|
-
throw new Error("Ephemeral messages cannot be pinned");
|
|
616
|
-
}
|
|
617
|
-
return this._client.pinMessage.call(this._client, this.channel.id, this.id);
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
/**
|
|
621
|
-
* Remove a reaction from a message
|
|
622
|
-
* @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
|
|
623
|
-
* @arg {String} [userID="@me"] The ID of the user to remove the reaction for
|
|
624
|
-
* @returns {Promise}
|
|
625
|
-
*/
|
|
626
|
-
removeReaction(reaction, userID) {
|
|
627
|
-
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
628
|
-
throw new Error("Ephemeral messages cannot have reactions");
|
|
629
|
-
}
|
|
630
|
-
return this._client.removeMessageReaction.call(this._client, this.channel.id, this.id, reaction, userID);
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* Remove all reactions from a message for a single emoji
|
|
635
|
-
* @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
|
|
636
|
-
* @returns {Promise}
|
|
637
|
-
*/
|
|
638
|
-
removeReactionEmoji(reaction) {
|
|
639
|
-
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
640
|
-
throw new Error("Ephemeral messages cannot have reactions");
|
|
641
|
-
}
|
|
642
|
-
return this._client.removeMessageReactionEmoji.call(this._client, this.channel.id, this.id, reaction);
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
/**
|
|
646
|
-
* Remove all reactions from a message
|
|
647
|
-
* @returns {Promise}
|
|
648
|
-
*/
|
|
649
|
-
removeReactions() {
|
|
650
|
-
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
651
|
-
throw new Error("Ephemeral messages cannot have reactions");
|
|
652
|
-
}
|
|
653
|
-
return this._client.removeMessageReactions.call(this._client, this.channel.id, this.id);
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
/**
|
|
657
|
-
* Unpin the message
|
|
658
|
-
* @returns {Promise}
|
|
659
|
-
*/
|
|
660
|
-
unpin() {
|
|
661
|
-
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
662
|
-
throw new Error("Ephemeral messages cannot be pinned");
|
|
663
|
-
}
|
|
664
|
-
return this._client.unpinMessage.call(this._client, this.channel.id, this.id);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
toJSON(props = []) {
|
|
668
|
-
return super.toJSON([
|
|
669
|
-
"activity",
|
|
670
|
-
"application",
|
|
671
|
-
"attachments",
|
|
672
|
-
"author",
|
|
673
|
-
"call",
|
|
674
|
-
"content",
|
|
675
|
-
"editedTimestamp",
|
|
676
|
-
"embeds",
|
|
677
|
-
"flags",
|
|
678
|
-
"guildID",
|
|
679
|
-
"interactionMetadata",
|
|
680
|
-
"member",
|
|
681
|
-
"mentionEveryone",
|
|
682
|
-
"mentions",
|
|
683
|
-
"messageReference",
|
|
684
|
-
"nonce",
|
|
685
|
-
"pinned",
|
|
686
|
-
"poll",
|
|
687
|
-
"position",
|
|
688
|
-
"reactions",
|
|
689
|
-
"referencedMessage",
|
|
690
|
-
"roleMentions",
|
|
691
|
-
"roleSubscriptionData",
|
|
692
|
-
"sharedClientTheme",
|
|
693
|
-
"stickers",
|
|
694
|
-
"stickerItems",
|
|
695
|
-
"thread",
|
|
696
|
-
"timestamp",
|
|
697
|
-
"tts",
|
|
698
|
-
"type",
|
|
699
|
-
"webhookID",
|
|
700
|
-
...props,
|
|
701
|
-
]);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
module.exports = Message;
|
|
706
|
-
|
|
707
|
-
// Circular import
|
|
708
|
-
const Channel = require("./Channel");
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Base = require("./Base");
|
|
4
|
+
const Collection = require("../util/Collection");
|
|
5
|
+
const Endpoints = require("../rest/Endpoints");
|
|
6
|
+
const Member = require("./Member");
|
|
7
|
+
const { ApplicationIntegrationTypes, InteractionTypes, MessageFlags } = require("../Constants");
|
|
8
|
+
const Role = require("./Role");
|
|
9
|
+
const User = require("./User");
|
|
10
|
+
|
|
11
|
+
function parseInteractionMetadata(client, data) {
|
|
12
|
+
const owners = data.authorizing_integration_owners || {};
|
|
13
|
+
const metadata = {
|
|
14
|
+
authorizingIntegrationOwners: {
|
|
15
|
+
guildInstall: owners[ApplicationIntegrationTypes.GUILD_INSTALL],
|
|
16
|
+
userInstall: owners[ApplicationIntegrationTypes.USER_INSTALL],
|
|
17
|
+
},
|
|
18
|
+
id: data.id,
|
|
19
|
+
type: data.type,
|
|
20
|
+
user: client.users.update(data.user, client),
|
|
21
|
+
};
|
|
22
|
+
if (data.original_response_message_id !== undefined) {
|
|
23
|
+
metadata.originalResponseMessageID = data.original_response_message_id;
|
|
24
|
+
}
|
|
25
|
+
if (data.type === InteractionTypes.APPLICATION_COMMAND) {
|
|
26
|
+
if (data.target_user !== undefined) {
|
|
27
|
+
metadata.targetUser = client.users.update(data.target_user, client);
|
|
28
|
+
}
|
|
29
|
+
if (data.target_message_id !== undefined) {
|
|
30
|
+
metadata.targetMessageID = data.target_message_id;
|
|
31
|
+
}
|
|
32
|
+
} else if (data.type === InteractionTypes.MESSAGE_COMPONENT) {
|
|
33
|
+
metadata.interactedMessageID = data.interacted_message_id;
|
|
34
|
+
} else if (data.type === InteractionTypes.MODAL_SUBMIT && data.triggering_interaction_metadata) {
|
|
35
|
+
metadata.triggeringInteractionMetadata = parseInteractionMetadata(client, data.triggering_interaction_metadata);
|
|
36
|
+
}
|
|
37
|
+
return metadata;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Represents a message
|
|
42
|
+
* @prop {Object?} activity The activity specified in the message
|
|
43
|
+
* @prop {Object?} application The application of the activity in the message
|
|
44
|
+
* @prop {String?} applicationID The ID of the interaction's application
|
|
45
|
+
* @prop {Array<Object>} attachments Array of attachments
|
|
46
|
+
* @prop {User} author The message author
|
|
47
|
+
* @prop {Object} call The call associated with the message
|
|
48
|
+
* @prop {Number?} call.endedTimestamp The time when the call ended
|
|
49
|
+
* @prop {Array<String>} call.participants An array of user IDs that participated in the call
|
|
50
|
+
* @prop {DMChannel | TextChannel | NewsChannel} channel The channel the message is in. Can be partial with only the id if the channel is not cached.
|
|
51
|
+
* @prop {Array<String>} channelMentions Array of mentions channels' ids
|
|
52
|
+
* @prop {String?} cleanContent Message content with mentions replaced by names. Mentions are currently escaped, but this behavior is [DEPRECATED] and will be removed soon. Use allowed mentions, the official way of avoiding unintended mentions, when creating messages.
|
|
53
|
+
* @prop {Command?} command The Command used in the Message, if any (CommandClient only)
|
|
54
|
+
* @prop {Array<Object>} components An array of component objects
|
|
55
|
+
* @prop {String} content Message content
|
|
56
|
+
* @prop {Number} createdAt Timestamp of message creation
|
|
57
|
+
* @prop {Number?} editedTimestamp Timestamp of latest message edit
|
|
58
|
+
* @prop {Array<Object>} embeds Array of embeds
|
|
59
|
+
* @prop {Number} flags Message flags (see constants)
|
|
60
|
+
* @prop {String?} guildID The ID of the guild this message is in (undefined if in DMs)
|
|
61
|
+
* @prop {String} id The ID of the message
|
|
62
|
+
* @prop {Object?} interaction [DEPRECATED] An object containing info about the interaction the message is responding to, if applicable. Use `interactionMetadata` instead
|
|
63
|
+
* @prop {String} interaction.id The ID of the interaction
|
|
64
|
+
* @prop {Member?} interaction.member The member who invoked the interaction
|
|
65
|
+
* @prop {String} interaction.name The name of the command
|
|
66
|
+
* @prop {Number} interaction.type The type of interaction
|
|
67
|
+
* @prop {User} interaction.user The user who invoked the interaction
|
|
68
|
+
* @prop {Object?} interactionMetadata Metadata about the interaction the message was sent as a result of, if applicable
|
|
69
|
+
* @prop {Object} interactionMetadata.authorizingIntegrationOwners The IDs of the installation contexts that authorized the app (`guildInstall` and/or `userInstall`)
|
|
70
|
+
* @prop {String} interactionMetadata.id The ID of the interaction
|
|
71
|
+
* @prop {String?} interactionMetadata.interactedMessageID The ID of the message that contained the interactive component (message component interactions only)
|
|
72
|
+
* @prop {String?} interactionMetadata.originalResponseMessageID The ID of the original response message (followup messages only)
|
|
73
|
+
* @prop {String?} interactionMetadata.targetMessageID The ID of the message the command was run on (message command interactions only)
|
|
74
|
+
* @prop {User?} interactionMetadata.targetUser The user the command was run on (user command interactions only)
|
|
75
|
+
* @prop {Object?} interactionMetadata.triggeringInteractionMetadata The metadata of the interaction that opened the modal (modal submit interactions only)
|
|
76
|
+
* @prop {Number} interactionMetadata.type The type of the interaction
|
|
77
|
+
* @prop {User} interactionMetadata.user The user who triggered the interaction
|
|
78
|
+
* @prop {String} jumpLink The url used by Discord clients to jump to this message
|
|
79
|
+
* @prop {Member?} member The message author with server-specific data
|
|
80
|
+
* @prop {Boolean} mentionEveryone Whether the message mentions everyone/here or not
|
|
81
|
+
* @prop {Array<User>} mentions Array of mentioned users
|
|
82
|
+
* @prop {Object?} messageReference An object containing the reference to the original message if it is a crossposted message, reply or forwarded message
|
|
83
|
+
* @prop {String} messageReference.channelID The ID of the channel this message was crossposted from
|
|
84
|
+
* @prop {String?} messageReference.guildID The ID of the guild this message was crossposted from
|
|
85
|
+
* @prop {String?} messageReference.messageID The ID of the original message this message was crossposted from
|
|
86
|
+
* @prop {Number} messageReference.type The type of reference. Either `0` (REPLY) or `1` (FORWARDED)
|
|
87
|
+
* @prop {Array<Object>?} messageSnapshots The message associated with the messageReference
|
|
88
|
+
* @prop {String?} messageSnapshots.guildID The ID of the guild this message originated from
|
|
89
|
+
* @prop {Message} messageSnapshots.message Subset of message fields. The list of message fields subset consists of: `attachments`, `content`, `edited_timestamp`, `embeds`, `flags`, `id`, `mentions`, `roleMentions`, `timestamp` and `type`
|
|
90
|
+
* @prop {(String | Number)?} nonce The nonce used to validate that the message was sent
|
|
91
|
+
* @prop {Boolean} pinned Whether the message is pinned or not
|
|
92
|
+
* @prop {Number?} position The approximate position of the message in a thread. Can be used to estimate the relative position of the message in a thread in company with the `totalMessageSent` property of the parent thread
|
|
93
|
+
* @prop {Object?} poll A poll object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/poll#poll-object) for object structure. Note: `poll.expiry` is an int, not ISO8601 as mentioned in Discord docs
|
|
94
|
+
* @prop {String?} prefix The prefix used in the Message, if any (CommandClient only)
|
|
95
|
+
* @prop {Object} reactions An object containing the reactions on the message. Each key is a reaction emoji and each value is an object with properties `burst_colors` (Array<String>), `count` (Number), `count_details` (an object with `burst` and `normal` keys corresponding to the amount of reactions), `me` (Boolean) and `me_burst` for that specific reaction emoji.
|
|
96
|
+
* @prop {Message?} referencedMessage The message that was replied to. If undefined, message data was not received. If null, the message was deleted.
|
|
97
|
+
* @prop {Array<String>} roleMentions Array of mentioned roles' ids
|
|
98
|
+
* @prop {Object?} resolved The resolved users, members, channels and roles referenced in the message's auto-populated select menus
|
|
99
|
+
* @prop {Collection<Channel>?} resolved.channels The resolved channels
|
|
100
|
+
* @prop {Collection<Member>?} resolved.members The resolved members
|
|
101
|
+
* @prop {Collection<Role>?} resolved.roles The resolved roles
|
|
102
|
+
* @prop {Collection<User>?} resolved.users The resolved users
|
|
103
|
+
* @prop {Object?} roleSubscriptionData The data of the role subscription purchase or renewal that prompted this `ROLE_SUBSCRIPTION_PURCHASE` message
|
|
104
|
+
* @prop {Boolean} roleSubscriptionData.isRenewal Whether this notification is for a renewal rather than a new purchase
|
|
105
|
+
* @prop {String} roleSubscriptionData.roleSubscriptionListingID The ID of the SKU and listing that the user is subscribed to
|
|
106
|
+
* @prop {String} roleSubscriptionData.tierName The name of the tier that the user is subscribed to
|
|
107
|
+
* @prop {Number} roleSubscriptionData.totalMonthsSubscribed The cumulative number of months that the user has been subscribed for
|
|
108
|
+
* @prop {Object?} sharedClientTheme The custom client-side theme shared via the message
|
|
109
|
+
* @prop {Number} sharedClientTheme.baseMix The intensity of the theme colors (0-100)
|
|
110
|
+
* @prop {Number?} sharedClientTheme.baseTheme The mode of the theme. See `Constants.BaseThemeTypes`
|
|
111
|
+
* @prop {Array<String>} sharedClientTheme.colors The hexadecimal-encoded colors of the theme (max of 5)
|
|
112
|
+
* @prop {Number} sharedClientTheme.gradientAngle The direction of the theme's colors (0-360)
|
|
113
|
+
* @prop {Array<Object>?} stickers [DEPRECATED] The stickers sent with the message
|
|
114
|
+
* @prop {Array<Object>?} stickerItems The stickers sent with the message
|
|
115
|
+
* @prop {ThreadChannel?} thread The thread that was started from this message
|
|
116
|
+
* @prop {Number} timestamp Timestamp of message creation
|
|
117
|
+
* @prop {Boolean} tts Whether to play the message using TTS or not
|
|
118
|
+
* @prop {Number} type The type of the message
|
|
119
|
+
* @prop {String?} webhookID ID of the webhook that sent the message
|
|
120
|
+
*/
|
|
121
|
+
class Message extends Base {
|
|
122
|
+
constructor(data, client) {
|
|
123
|
+
super(data.id);
|
|
124
|
+
this._client = client;
|
|
125
|
+
this.type = data.type || 0;
|
|
126
|
+
this.timestamp = Date.parse(data.timestamp);
|
|
127
|
+
this.channel = this._client.getChannel(data.channel_id) || {
|
|
128
|
+
id: data.channel_id,
|
|
129
|
+
};
|
|
130
|
+
this.content = "";
|
|
131
|
+
this.reactions = {};
|
|
132
|
+
this.guildID = data.guild_id;
|
|
133
|
+
this.webhookID = data.webhook_id;
|
|
134
|
+
|
|
135
|
+
if (data.message_reference) {
|
|
136
|
+
this.messageReference = {
|
|
137
|
+
type: data.message_reference.type,
|
|
138
|
+
messageID: data.message_reference.message_id,
|
|
139
|
+
channelID: data.message_reference.channel_id,
|
|
140
|
+
guildID: data.message_reference.guild_id,
|
|
141
|
+
};
|
|
142
|
+
} else {
|
|
143
|
+
this.messageReference = null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (data.message_snapshots && this.messageReference) {
|
|
147
|
+
this.messageSnapshots = data.message_snapshots.map((snapshot) => {
|
|
148
|
+
snapshot.message.id = this.messageReference.messageID;
|
|
149
|
+
snapshot.message.channel_id = this.messageReference.channelID;
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
guildID: this.messageReference.guildID,
|
|
153
|
+
message: new Message(snapshot.message, this._client),
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
this.flags = data.flags || 0;
|
|
159
|
+
|
|
160
|
+
if (data.author) {
|
|
161
|
+
if (data.author.discriminator !== "0000") {
|
|
162
|
+
this.author = this._client.users.update(data.author, client);
|
|
163
|
+
} else {
|
|
164
|
+
this.author = new User(data.author, client);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (data.referenced_message) {
|
|
169
|
+
const channel = this._client.getChannel(data.referenced_message.channel_id);
|
|
170
|
+
if (channel) {
|
|
171
|
+
this.referencedMessage = channel.messages.update(data.referenced_message, this._client);
|
|
172
|
+
} else {
|
|
173
|
+
this.referencedMessage = new Message(data.referenced_message, this._client);
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
this.referencedMessage = data.referenced_message;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (data.interaction) {
|
|
180
|
+
this.interaction = data.interaction;
|
|
181
|
+
let interactionMember;
|
|
182
|
+
const interactionUser = this._client.users.update(data.interaction.user, client);
|
|
183
|
+
if (data.interaction.member) {
|
|
184
|
+
data.interaction.member.id = data.interaction.user.id;
|
|
185
|
+
if (this.channel.guild) {
|
|
186
|
+
interactionMember = this.channel.guild.members.update(data.interaction.member, this.channel.guild);
|
|
187
|
+
} else {
|
|
188
|
+
interactionMember = data.interaction.member;
|
|
189
|
+
}
|
|
190
|
+
} else if (this.channel.guild && this.channel.guild.members.has(data.interaction.user.id)) {
|
|
191
|
+
interactionMember = this.channel.guild.members.get(data.interaction.user.id);
|
|
192
|
+
} else {
|
|
193
|
+
interactionMember = null;
|
|
194
|
+
}
|
|
195
|
+
this.interaction.user = interactionUser;
|
|
196
|
+
this.interaction.member = interactionMember;
|
|
197
|
+
} else {
|
|
198
|
+
this.interaction = null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (data.interaction_metadata) {
|
|
202
|
+
this.interactionMetadata = parseInteractionMetadata(this._client, data.interaction_metadata);
|
|
203
|
+
} else {
|
|
204
|
+
this.interactionMetadata = null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (data.nonce !== undefined) {
|
|
208
|
+
this.nonce = data.nonce;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (this.channel.guild) {
|
|
212
|
+
if (data.member) {
|
|
213
|
+
data.member.id = this.author.id;
|
|
214
|
+
if (data.author) {
|
|
215
|
+
data.member.user = data.author;
|
|
216
|
+
}
|
|
217
|
+
this.member = this.channel.guild.members.update(data.member, this.channel.guild);
|
|
218
|
+
} else if (this.author && this.channel.guild.members.has(this.author.id)) {
|
|
219
|
+
this.member = this.channel.guild.members.get(this.author.id);
|
|
220
|
+
} else {
|
|
221
|
+
this.member = null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (!this.guildID) {
|
|
225
|
+
this.guildID = this.channel.guild.id;
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
this.member = null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
this.update(data, client);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
update(data, client) {
|
|
235
|
+
if (data.content !== undefined) {
|
|
236
|
+
this.content = data.content || "";
|
|
237
|
+
this.mentionEveryone = !!data.mention_everyone;
|
|
238
|
+
|
|
239
|
+
this.mentions = data.mentions.map((mention) => {
|
|
240
|
+
const user = this._client.users.add(mention, client);
|
|
241
|
+
if (mention.member && this.channel.guild) {
|
|
242
|
+
mention.member.id = mention.id;
|
|
243
|
+
this.channel.guild.members.update(mention.member, this.channel.guild);
|
|
244
|
+
}
|
|
245
|
+
return user;
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
this.roleMentions = data.mention_roles;
|
|
249
|
+
}
|
|
250
|
+
if (data.poll !== undefined) {
|
|
251
|
+
this.poll = data.poll;
|
|
252
|
+
if (data.poll.expiry !== null) {
|
|
253
|
+
this.poll.expiry = Date.parse(data.poll.expiry);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (data.pinned !== undefined) {
|
|
257
|
+
this.pinned = !!data.pinned;
|
|
258
|
+
}
|
|
259
|
+
if (data.edited_timestamp != undefined) {
|
|
260
|
+
this.editedTimestamp = Date.parse(data.edited_timestamp);
|
|
261
|
+
}
|
|
262
|
+
if (data.tts !== undefined) {
|
|
263
|
+
this.tts = data.tts;
|
|
264
|
+
}
|
|
265
|
+
if (data.attachments !== undefined) {
|
|
266
|
+
this.attachments = data.attachments;
|
|
267
|
+
}
|
|
268
|
+
if (data.embeds !== undefined) {
|
|
269
|
+
this.embeds = data.embeds;
|
|
270
|
+
}
|
|
271
|
+
if (data.flags !== undefined) {
|
|
272
|
+
this.flags = data.flags;
|
|
273
|
+
}
|
|
274
|
+
if (data.activity !== undefined) {
|
|
275
|
+
this.activity = data.activity;
|
|
276
|
+
}
|
|
277
|
+
if (data.application !== undefined) {
|
|
278
|
+
this.application = data.application;
|
|
279
|
+
}
|
|
280
|
+
if (data.application_id !== undefined) {
|
|
281
|
+
this.applicationID = data.application_id;
|
|
282
|
+
}
|
|
283
|
+
if (data.reactions) {
|
|
284
|
+
data.reactions.forEach((reaction) => {
|
|
285
|
+
this.reactions[reaction.emoji.id ? `${reaction.emoji.name}:${reaction.emoji.id}` : reaction.emoji.name] = {
|
|
286
|
+
burst_colors: reaction.burst_colors,
|
|
287
|
+
count: reaction.count,
|
|
288
|
+
count_details: reaction.count_details,
|
|
289
|
+
me: reaction.me,
|
|
290
|
+
me_burst: reaction.me_burst,
|
|
291
|
+
};
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
if (data.stickers !== undefined) {
|
|
295
|
+
this.stickers = data.stickers;
|
|
296
|
+
}
|
|
297
|
+
if (data.sticker_items !== undefined) {
|
|
298
|
+
this.stickerItems = data.sticker_items.map((sticker) => {
|
|
299
|
+
if (sticker.user) {
|
|
300
|
+
sticker.user = this._client.users.update(sticker.user, client);
|
|
301
|
+
}
|
|
302
|
+
return sticker;
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
if (data.components !== undefined) {
|
|
306
|
+
this.components = data.components;
|
|
307
|
+
}
|
|
308
|
+
if (data.call !== undefined) {
|
|
309
|
+
this.call = {
|
|
310
|
+
endedTimestamp: Date.parse(data.call.ended_timestamp) || null,
|
|
311
|
+
participants: data.call.participants,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
if (data.position !== undefined) {
|
|
315
|
+
this.position = data.position;
|
|
316
|
+
}
|
|
317
|
+
if (data.resolved !== undefined) {
|
|
318
|
+
const guild = this.channel.guild || this._client.guilds.get(this.guildID);
|
|
319
|
+
this.resolved = {};
|
|
320
|
+
if (data.resolved.users !== undefined) {
|
|
321
|
+
this.resolved.users = new Collection(User);
|
|
322
|
+
Object.entries(data.resolved.users).forEach(([id, user]) => {
|
|
323
|
+
this.resolved.users.set(id, this._client.users.update(user, this._client));
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
if (data.resolved.members !== undefined && guild) {
|
|
327
|
+
this.resolved.members = new Collection(Member);
|
|
328
|
+
Object.entries(data.resolved.members).forEach(([id, member]) => {
|
|
329
|
+
const memberData = Object.assign({}, member);
|
|
330
|
+
memberData.id = id;
|
|
331
|
+
memberData.user = { id };
|
|
332
|
+
this.resolved.members.set(id, guild.members.update(memberData, guild));
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
if (data.resolved.roles !== undefined) {
|
|
336
|
+
this.resolved.roles = new Collection(Role);
|
|
337
|
+
Object.entries(data.resolved.roles).forEach(([id, role]) => {
|
|
338
|
+
this.resolved.roles.set(id, new Role(role, guild || {
|
|
339
|
+
id: this.guildID,
|
|
340
|
+
}));
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
if (data.resolved.channels !== undefined) {
|
|
344
|
+
this.resolved.channels = new Collection(Channel);
|
|
345
|
+
Object.entries(data.resolved.channels).forEach(([id, channel]) => {
|
|
346
|
+
this.resolved.channels.set(id, this._client.getChannel(id) || new Channel(channel, this._client));
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (data.role_subscription_data !== undefined) {
|
|
351
|
+
this.roleSubscriptionData = {
|
|
352
|
+
isRenewal: data.role_subscription_data.is_renewal,
|
|
353
|
+
roleSubscriptionListingID: data.role_subscription_data.role_subscription_listing_id,
|
|
354
|
+
tierName: data.role_subscription_data.tier_name,
|
|
355
|
+
totalMonthsSubscribed: data.role_subscription_data.total_months_subscribed,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
if (data.shared_client_theme !== undefined) {
|
|
359
|
+
this.sharedClientTheme = data.shared_client_theme && {
|
|
360
|
+
baseMix: data.shared_client_theme.base_mix,
|
|
361
|
+
baseTheme: data.shared_client_theme.base_theme,
|
|
362
|
+
colors: data.shared_client_theme.colors,
|
|
363
|
+
gradientAngle: data.shared_client_theme.gradient_angle,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
if (data.thread !== undefined) {
|
|
367
|
+
const thread = this._client.getChannel(data.thread.id);
|
|
368
|
+
if (thread) {
|
|
369
|
+
thread.update(data.thread);
|
|
370
|
+
this.thread = thread;
|
|
371
|
+
} else {
|
|
372
|
+
this.thread = Channel.from(data.thread, this._client);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
get channelMentions() {
|
|
378
|
+
if (this._channelMentions) {
|
|
379
|
+
return this._channelMentions;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return (this._channelMentions = ((this.content && this.content.match(/<#[0-9]+>/g)) || []).map((mention) => mention.substring(2, mention.length - 1)));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
get cleanContent() {
|
|
386
|
+
let cleanContent = (this.content && this.content.replace(/<a?(:\w+:)[0-9]+>/g, "$1")) || "";
|
|
387
|
+
|
|
388
|
+
let authorName = this.author.username;
|
|
389
|
+
if (this.channel.guild) {
|
|
390
|
+
const member = this.channel.guild.members.get(this.author.id);
|
|
391
|
+
if (member && member.nick) {
|
|
392
|
+
authorName = member.nick;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
cleanContent = cleanContent.replace(new RegExp(`<@!?${this.author.id}>`, "g"), "@\u200b" + authorName);
|
|
396
|
+
|
|
397
|
+
if (this.mentions) {
|
|
398
|
+
this.mentions.forEach((mention) => {
|
|
399
|
+
if (this.channel.guild) {
|
|
400
|
+
const member = this.channel.guild.members.get(mention.id);
|
|
401
|
+
if (member && member.nick) {
|
|
402
|
+
cleanContent = cleanContent.replace(new RegExp(`<@!?${mention.id}>`, "g"), "@\u200b" + member.nick);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
cleanContent = cleanContent.replace(new RegExp(`<@!?${mention.id}>`, "g"), "@\u200b" + mention.username);
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (this.channel.guild && this.roleMentions) {
|
|
410
|
+
for (const roleID of this.roleMentions) {
|
|
411
|
+
const role = this.channel.guild.roles.get(roleID);
|
|
412
|
+
const roleName = role ? role.name : "deleted-role";
|
|
413
|
+
cleanContent = cleanContent.replace(new RegExp(`<@&${roleID}>`, "g"), "@\u200b" + roleName);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
this.channelMentions.forEach((id) => {
|
|
418
|
+
const channel = this._client.getChannel(id);
|
|
419
|
+
if (channel && channel.name && channel.mention) {
|
|
420
|
+
cleanContent = cleanContent.replace(channel.mention, "#" + channel.name);
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
return cleanContent.replace(/@everyone/g, "@\u200beveryone").replace(/@here/g, "@\u200bhere");
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
get jumpLink() {
|
|
428
|
+
return `${Endpoints.CLIENT_URL}${Endpoints.MESSAGE_LINK(this.guildID || "@me", this.channel.id, this.id)}`; // Messages outside of guilds (DMs) will never have a guildID property assigned
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Add a reaction to a message
|
|
433
|
+
* @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
|
|
434
|
+
* @returns {Promise}
|
|
435
|
+
*/
|
|
436
|
+
addReaction(reaction) {
|
|
437
|
+
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
438
|
+
throw new Error("Ephemeral messages cannot have reactions");
|
|
439
|
+
}
|
|
440
|
+
return this._client.addMessageReaction.call(this._client, this.channel.id, this.id, reaction);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Create a thread with this message
|
|
445
|
+
* @arg {Object} options The thread options
|
|
446
|
+
* @arg {Number} [options.autoArchiveDuration] Duration in minutes to automatically archive the thread after recent activity, either 60, 1440, 4320 or 10080
|
|
447
|
+
* @arg {String} options.name The thread channel name
|
|
448
|
+
* @arg {Number} [options.rateLimitPerUser] The time in seconds a user has to wait before sending another message (0-21600) (does not affect bots or users with manageMessages/manageChannel permissions)
|
|
449
|
+
* @arg {String} [options.reason] The reason to be displayed in audit logs
|
|
450
|
+
* @returns {Promise<NewsThreadChannel | PublicThreadChannel>}
|
|
451
|
+
*/
|
|
452
|
+
createThreadWithMessage(options) {
|
|
453
|
+
return this._client.createThreadWithMessage.call(this._client, this.channel.id, this.id, options);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Crosspost (publish) a message to subscribed channels (NewsChannel only)
|
|
458
|
+
* @returns {Promise<Message>}
|
|
459
|
+
*/
|
|
460
|
+
crosspost() {
|
|
461
|
+
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
462
|
+
throw new Error("Ephemeral messages cannot be crossposted");
|
|
463
|
+
}
|
|
464
|
+
return this._client.crosspostMessage.call(this._client, this.channel.id, this.id);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Delete the message
|
|
469
|
+
* @arg {String} [reason] The reason to be displayed in audit logs
|
|
470
|
+
* @returns {Promise}
|
|
471
|
+
*/
|
|
472
|
+
delete(reason) {
|
|
473
|
+
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
474
|
+
throw new Error("Ephemeral messages cannot be deleted");
|
|
475
|
+
}
|
|
476
|
+
return this._client.deleteMessage.call(this._client, this.channel.id, this.id, reason);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Delete the message as a webhook
|
|
481
|
+
* @arg {String} token The token of the webhook
|
|
482
|
+
* @returns {Promise}
|
|
483
|
+
*/
|
|
484
|
+
deleteWebhook(token) {
|
|
485
|
+
if (!this.webhookID) {
|
|
486
|
+
throw new Error("Message is not a webhook");
|
|
487
|
+
}
|
|
488
|
+
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
489
|
+
throw new Error("Ephemeral messages cannot be deleted");
|
|
490
|
+
}
|
|
491
|
+
return this._client.deleteWebhookMessage.call(this._client, this.webhookID, token, this.id);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Edit the message
|
|
496
|
+
* @arg {String | Array | Object} content A string, array of strings, or object. If an object is passed:
|
|
497
|
+
* @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
|
|
498
|
+
* @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here
|
|
499
|
+
* @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
|
|
500
|
+
* @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
|
|
501
|
+
* @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
|
|
502
|
+
* @arg {String} [content.attachments[].description] The description of the file
|
|
503
|
+
* @arg {String} [content.attachments[].filename] The name of the file. This is not required if you are attaching a new file
|
|
504
|
+
* @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
|
|
505
|
+
* @arg {Array<Object>} [content.components] An array of component objects
|
|
506
|
+
* @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
|
|
507
|
+
* @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3,5,6,7,8 only)
|
|
508
|
+
* @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
|
|
509
|
+
* @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
|
|
510
|
+
* @arg {Array<Object>} [content.components[].default_values] default values for the component (type 5,6,7,8 only)
|
|
511
|
+
* @arg {String} [content.components[].default_values[].id] id of a user, role, or channel
|
|
512
|
+
* @arg {String} [content.components[].default_values[].type] type of value that id represents (user, role, or channel)
|
|
513
|
+
* @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
|
|
514
|
+
* @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
|
|
515
|
+
* @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
|
|
516
|
+
* @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
|
|
517
|
+
* @arg {String} [content.components[].options[].description] The description for this option
|
|
518
|
+
* @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
|
|
519
|
+
* @arg {String} content.components[].options[].label The label for this option
|
|
520
|
+
* @arg {Number | String} content.components[].options[].value The value for this option
|
|
521
|
+
* @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
|
|
522
|
+
* @arg {String} [content.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
|
|
523
|
+
* @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
|
|
524
|
+
* @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)
|
|
525
|
+
* @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
|
|
526
|
+
* @arg {String} [content.content] A content string
|
|
527
|
+
* @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
|
|
528
|
+
* @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
|
|
529
|
+
* @arg {Object | Array<Object>} [content.file] A file object (or an Array of them)
|
|
530
|
+
* @arg {Buffer} content.file[].file A buffer containing file data
|
|
531
|
+
* @arg {String} content.file[].name What to name the file
|
|
532
|
+
* @arg {Number} [content.flags] A number representing the flags to apply to the message. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#message-object-message-flags) for flags reference
|
|
533
|
+
* @returns {Promise<Message>}
|
|
534
|
+
*/
|
|
535
|
+
edit(content) {
|
|
536
|
+
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
537
|
+
throw new Error("Ephemeral messages cannot be edited via this method");
|
|
538
|
+
}
|
|
539
|
+
return this._client.editMessage.call(this._client, this.channel.id, this.id, content);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Edit the message as a webhook
|
|
544
|
+
* @arg {String} token The token of the webhook
|
|
545
|
+
* @arg {Object} options Webhook message edit options
|
|
546
|
+
* @arg {Object} [options.allowedMentions] A list of mentions to allow (overrides default)
|
|
547
|
+
* @arg {Boolean} [options.allowedMentions.everyone] Whether or not to allow @everyone/@here
|
|
548
|
+
* @arg {Boolean} [options.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to
|
|
549
|
+
* @arg {Boolean | Array<String>} [options.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow
|
|
550
|
+
* @arg {Boolean | Array<String>} [options.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow
|
|
551
|
+
* @arg {Array<Object>} [options.attachments] An array of attachment objects that will be appended to the message, including new files. Only the provided files will be appended
|
|
552
|
+
* @arg {String} [options.attachments[].description] The description of the file
|
|
553
|
+
* @arg {String} [options.attachments[].filename] The name of the file. This is not required if you are attaching a new file
|
|
554
|
+
* @arg {Number | String} options.attachments[].id The ID of the file. If you are attaching a new file, this would be the index of the file
|
|
555
|
+
* @arg {Array<Object>} [options.components] An array of component objects
|
|
556
|
+
* @arg {String} [options.components[].custom_id] The ID of the component (type 2 style 1-4 and type 3,5,6,7,8 only)
|
|
557
|
+
* @arg {Boolean} [options.components[].disabled] Whether the component is disabled (type 2 and type 3,5,6,7,8 only)
|
|
558
|
+
* @arg {Object} [options.components[].emoji] The emoji to be displayed in the component (type 2)
|
|
559
|
+
* @arg {String} [options.components[].label] The label to be displayed in the component (type 2)
|
|
560
|
+
* @arg {Array<Object>} [options.components[].default_values] default values for the component (type 5,6,7,8 only)
|
|
561
|
+
* @arg {String} [options.components[].default_values[].id] id of a user, role, or channel
|
|
562
|
+
* @arg {String} [options.components[].default_values[].type] type of value that id represents (user, role, or channel)
|
|
563
|
+
* @arg {Number} [options.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
|
|
564
|
+
* @arg {Number} [options.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
|
|
565
|
+
* @arg {Array<Object>} [options.components[].options] The options for this component (type 3 only)
|
|
566
|
+
* @arg {Boolean} [options.components[].options[].default] Whether this option should be the default value selected
|
|
567
|
+
* @arg {String} [options.components[].options[].description] The description for this option
|
|
568
|
+
* @arg {Object} [options.components[].options[].emoji] The emoji to be displayed in this option
|
|
569
|
+
* @arg {String} options.components[].options[].label The label for this option
|
|
570
|
+
* @arg {Number | String} options.components[].options[].value The value for this option
|
|
571
|
+
* @arg {String} [options.components[].placeholder] The placeholder text for the component when no option is selected (type 3,5,6,7,8 only)
|
|
572
|
+
* @arg {String} [options.components[].sku_id] The ID of the SKU to purchase (type 2 style 6 only)
|
|
573
|
+
* @arg {Number} [options.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
|
|
574
|
+
* @arg {Number} options.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)
|
|
575
|
+
* @arg {String} [options.components[].url] The URL that the component should open for users (type 2 style 5 only)
|
|
576
|
+
* @arg {String} [options.content] A content string
|
|
577
|
+
* @arg {Object} [options.embed] [DEPRECATED] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
|
|
578
|
+
* @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
|
|
579
|
+
* @arg {Object | Array<Object>} [options.file] A file object (or an Array of them)
|
|
580
|
+
* @arg {Buffer} options.file.file A buffer containing file data
|
|
581
|
+
* @arg {String} options.file.name What to name the file
|
|
582
|
+
* @returns {Promise<Message>}
|
|
583
|
+
*/
|
|
584
|
+
editWebhook(token, options) {
|
|
585
|
+
if (!this.webhookID) {
|
|
586
|
+
throw new Error("Message is not a webhook");
|
|
587
|
+
}
|
|
588
|
+
return this._client.editWebhookMessage.call(this._client, this.webhookID, token, this.id, options);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Get a list of users who reacted with a specific reaction
|
|
593
|
+
* @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
|
|
594
|
+
* @arg {Object} [options] Options for the request. If this is a number, it is treated as `options.limit` ([DEPRECATED] behavior)
|
|
595
|
+
* @arg {String} [options.after] Get users after this user ID
|
|
596
|
+
* @arg {Number} [options.limit=100] The maximum number of users to get
|
|
597
|
+
* @arg {Number} [options.type=0] The type of reaction (`0` for normal, `1` for burst)
|
|
598
|
+
* @arg {String} [before] [DEPRECATED] Get users before this user ID. Discord no longer supports this parameter
|
|
599
|
+
* @arg {String} [after] [DEPRECATED] Get users after this user ID
|
|
600
|
+
* @returns {Promise<Array<User>>}
|
|
601
|
+
*/
|
|
602
|
+
getReaction(reaction, options, before, after) {
|
|
603
|
+
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
604
|
+
throw new Error("Ephemeral messages cannot have reactions");
|
|
605
|
+
}
|
|
606
|
+
return this._client.getMessageReaction.call(this._client, this.channel.id, this.id, reaction, options, before, after);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Pin the message
|
|
611
|
+
* @returns {Promise}
|
|
612
|
+
*/
|
|
613
|
+
pin() {
|
|
614
|
+
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
615
|
+
throw new Error("Ephemeral messages cannot be pinned");
|
|
616
|
+
}
|
|
617
|
+
return this._client.pinMessage.call(this._client, this.channel.id, this.id);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Remove a reaction from a message
|
|
622
|
+
* @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
|
|
623
|
+
* @arg {String} [userID="@me"] The ID of the user to remove the reaction for
|
|
624
|
+
* @returns {Promise}
|
|
625
|
+
*/
|
|
626
|
+
removeReaction(reaction, userID) {
|
|
627
|
+
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
628
|
+
throw new Error("Ephemeral messages cannot have reactions");
|
|
629
|
+
}
|
|
630
|
+
return this._client.removeMessageReaction.call(this._client, this.channel.id, this.id, reaction, userID);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Remove all reactions from a message for a single emoji
|
|
635
|
+
* @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
|
|
636
|
+
* @returns {Promise}
|
|
637
|
+
*/
|
|
638
|
+
removeReactionEmoji(reaction) {
|
|
639
|
+
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
640
|
+
throw new Error("Ephemeral messages cannot have reactions");
|
|
641
|
+
}
|
|
642
|
+
return this._client.removeMessageReactionEmoji.call(this._client, this.channel.id, this.id, reaction);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Remove all reactions from a message
|
|
647
|
+
* @returns {Promise}
|
|
648
|
+
*/
|
|
649
|
+
removeReactions() {
|
|
650
|
+
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
651
|
+
throw new Error("Ephemeral messages cannot have reactions");
|
|
652
|
+
}
|
|
653
|
+
return this._client.removeMessageReactions.call(this._client, this.channel.id, this.id);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Unpin the message
|
|
658
|
+
* @returns {Promise}
|
|
659
|
+
*/
|
|
660
|
+
unpin() {
|
|
661
|
+
if (this.flags & MessageFlags.EPHEMERAL) {
|
|
662
|
+
throw new Error("Ephemeral messages cannot be pinned");
|
|
663
|
+
}
|
|
664
|
+
return this._client.unpinMessage.call(this._client, this.channel.id, this.id);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
toJSON(props = []) {
|
|
668
|
+
return super.toJSON([
|
|
669
|
+
"activity",
|
|
670
|
+
"application",
|
|
671
|
+
"attachments",
|
|
672
|
+
"author",
|
|
673
|
+
"call",
|
|
674
|
+
"content",
|
|
675
|
+
"editedTimestamp",
|
|
676
|
+
"embeds",
|
|
677
|
+
"flags",
|
|
678
|
+
"guildID",
|
|
679
|
+
"interactionMetadata",
|
|
680
|
+
"member",
|
|
681
|
+
"mentionEveryone",
|
|
682
|
+
"mentions",
|
|
683
|
+
"messageReference",
|
|
684
|
+
"nonce",
|
|
685
|
+
"pinned",
|
|
686
|
+
"poll",
|
|
687
|
+
"position",
|
|
688
|
+
"reactions",
|
|
689
|
+
"referencedMessage",
|
|
690
|
+
"roleMentions",
|
|
691
|
+
"roleSubscriptionData",
|
|
692
|
+
"sharedClientTheme",
|
|
693
|
+
"stickers",
|
|
694
|
+
"stickerItems",
|
|
695
|
+
"thread",
|
|
696
|
+
"timestamp",
|
|
697
|
+
"tts",
|
|
698
|
+
"type",
|
|
699
|
+
"webhookID",
|
|
700
|
+
...props,
|
|
701
|
+
]);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
module.exports = Message;
|
|
706
|
+
|
|
707
|
+
// Circular import
|
|
708
|
+
const Channel = require("./Channel");
|