@velliajs/discord 1.0.3 → 1.0.4
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/package.json +1 -1
- package/src/client/BaseClient.js +7 -28
- package/src/client/Client.js +116 -283
- package/src/client/WebhookClient.js +17 -59
- package/src/client/actions/Action.js +0 -10
- package/src/client/actions/ActionsManager.js +3 -3
- package/src/client/actions/ApplicationCommandPermissionsUpdate.js +2 -15
- package/src/client/actions/AutoModerationActionExecution.js +1 -6
- package/src/client/actions/AutoModerationRuleCreate.js +1 -6
- package/src/client/actions/AutoModerationRuleDelete.js +1 -6
- package/src/client/actions/AutoModerationRuleUpdate.js +1 -7
- package/src/client/actions/ChannelCreate.js +1 -5
- package/src/client/actions/ChannelDelete.js +1 -5
- package/src/client/actions/GuildAuditLogEntryCreate.js +1 -6
- package/src/client/actions/GuildBanAdd.js +1 -5
- package/src/client/actions/GuildBanRemove.js +1 -5
- package/src/client/actions/GuildDelete.js +6 -14
- package/src/client/actions/GuildEmojiCreate.js +1 -5
- package/src/client/actions/GuildEmojiDelete.js +1 -5
- package/src/client/actions/GuildEmojiUpdate.js +1 -6
- package/src/client/actions/GuildEmojisUpdate.js +4 -4
- package/src/client/actions/GuildIntegrationsUpdate.js +1 -5
- package/src/client/actions/GuildMemberRemove.js +1 -5
- package/src/client/actions/GuildMemberUpdate.js +2 -11
- package/src/client/actions/GuildRoleCreate.js +1 -5
- package/src/client/actions/GuildRoleDelete.js +1 -5
- package/src/client/actions/GuildRoleUpdate.js +1 -6
- package/src/client/actions/GuildScheduledEventCreate.js +1 -5
- package/src/client/actions/GuildScheduledEventDelete.js +1 -5
- package/src/client/actions/GuildScheduledEventUpdate.js +1 -6
- package/src/client/actions/GuildScheduledEventUserAdd.js +1 -6
- package/src/client/actions/GuildScheduledEventUserRemove.js +1 -6
- package/src/client/actions/GuildStickerCreate.js +1 -5
- package/src/client/actions/GuildStickerDelete.js +1 -5
- package/src/client/actions/GuildStickerUpdate.js +1 -6
- package/src/client/actions/GuildStickersUpdate.js +4 -4
- package/src/client/actions/GuildUpdate.js +1 -6
- package/src/client/actions/InteractionCreate.js +3 -7
- package/src/client/actions/InviteCreate.js +1 -7
- package/src/client/actions/InviteDelete.js +1 -7
- package/src/client/actions/MessageCreate.js +1 -5
- package/src/client/actions/MessageDelete.js +1 -5
- package/src/client/actions/MessageDeleteBulk.js +1 -6
- package/src/client/actions/MessageReactionAdd.js +5 -18
- package/src/client/actions/MessageReactionRemove.js +5 -16
- package/src/client/actions/MessageReactionRemoveAll.js +4 -9
- package/src/client/actions/MessageReactionRemoveEmoji.js +1 -5
- package/src/client/actions/PresenceUpdate.js +1 -6
- package/src/client/actions/StageInstanceCreate.js +1 -5
- package/src/client/actions/StageInstanceDelete.js +1 -5
- package/src/client/actions/StageInstanceUpdate.js +1 -6
- package/src/client/actions/ThreadCreate.js +1 -6
- package/src/client/actions/ThreadDelete.js +1 -5
- package/src/client/actions/ThreadListSync.js +2 -7
- package/src/client/actions/ThreadMemberUpdate.js +2 -7
- package/src/client/actions/ThreadMembersUpdate.js +2 -9
- package/src/client/actions/TypingStart.js +1 -5
- package/src/client/actions/UserUpdate.js +1 -8
- package/src/client/actions/VoiceStateUpdate.js +4 -9
- package/src/client/actions/WebhooksUpdate.js +1 -6
- package/src/client/voice/ClientVoiceManager.js +3 -13
- package/src/client/websocket/WebSocketManager.js +25 -117
- package/src/client/websocket/WebSocketShard.js +29 -116
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +2 -8
- package/src/client/websocket/handlers/CHANNEL_UPDATE.js +1 -6
- package/src/client/websocket/handlers/GUILD_CREATE.js +3 -7
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +2 -16
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +1 -5
- package/src/client/websocket/handlers/MESSAGE_UPDATE.js +1 -6
- package/src/client/websocket/handlers/RESUMED.js +1 -6
- package/src/client/websocket/handlers/THREAD_UPDATE.js +1 -6
- package/src/errors/DJSError.js +3 -14
- package/src/errors/ErrorCodes.js +2 -164
- package/src/index.js +6 -6
- package/src/managers/ApplicationCommandManager.js +14 -130
- package/src/managers/ApplicationCommandPermissionsManager.js +31 -202
- package/src/managers/AutoModerationRuleManager.js +17 -145
- package/src/managers/BaseGuildEmojiManager.js +7 -38
- package/src/managers/BaseManager.js +2 -10
- package/src/managers/CachedManager.js +3 -17
- package/src/managers/CategoryChannelChildManager.js +6 -48
- package/src/managers/ChannelManager.js +11 -52
- package/src/managers/DataManager.js +5 -27
- package/src/managers/GuildApplicationCommandManager.js +3 -12
- package/src/managers/GuildBanManager.js +16 -105
- package/src/managers/GuildChannelManager.js +31 -226
- package/src/managers/GuildEmojiManager.js +9 -65
- package/src/managers/GuildEmojiRoleManager.js +8 -47
- package/src/managers/GuildForumThreadManager.js +5 -39
- package/src/managers/GuildInviteManager.js +18 -117
- package/src/managers/GuildManager.js +14 -115
- package/src/managers/GuildMemberManager.js +38 -256
- package/src/managers/GuildMemberRoleManager.js +13 -76
- package/src/managers/GuildScheduledEventManager.js +25 -128
- package/src/managers/GuildStickerManager.js +16 -96
- package/src/managers/GuildTextThreadManager.js +4 -47
- package/src/managers/MessageManager.js +23 -137
- package/src/managers/PermissionOverwriteManager.js +10 -78
- package/src/managers/PresenceManager.js +6 -27
- package/src/managers/ReactionManager.js +7 -40
- package/src/managers/ReactionUserManager.js +6 -29
- package/src/managers/RoleManager.js +29 -177
- package/src/managers/StageInstanceManager.js +14 -77
- package/src/managers/ThreadManager.js +23 -113
- package/src/managers/ThreadMemberManager.js +20 -89
- package/src/managers/UserManager.js +13 -65
- package/src/managers/VoiceStateManager.js +3 -13
- package/src/sharding/Shard.js +42 -158
- package/src/sharding/ShardClientUtil.js +17 -101
- package/src/sharding/ShardingManager.js +34 -151
- package/src/structures/ActionRow.js +4 -21
- package/src/structures/ActionRowBuilder.js +3 -13
- package/src/structures/AnonymousGuild.js +10 -43
- package/src/structures/ApplicationCommand.js +54 -308
- package/src/structures/ApplicationRoleConnectionMetadata.js +7 -27
- package/src/structures/Attachment.js +16 -65
- package/src/structures/AttachmentBuilder.js +13 -58
- package/src/structures/AutoModerationActionExecution.js +16 -69
- package/src/structures/AutoModerationRule.js +32 -164
- package/src/structures/AutocompleteInteraction.js +10 -52
- package/src/structures/Base.js +2 -10
- package/src/structures/BaseChannel.js +16 -80
- package/src/structures/BaseGuild.js +13 -59
- package/src/structures/BaseGuildEmoji.js +5 -21
- package/src/structures/BaseGuildTextChannel.js +19 -100
- package/src/structures/BaseGuildVoiceChannel.js +21 -110
- package/src/structures/BaseInteraction.js +40 -196
- package/src/structures/BaseSelectMenuComponent.js +6 -29
- package/src/structures/ButtonBuilder.js +4 -18
- package/src/structures/ButtonComponent.js +7 -34
- package/src/structures/ButtonInteraction.js +1 -4
- package/src/structures/CategoryChannel.js +5 -30
- package/src/structures/ChannelSelectMenuBuilder.js +3 -13
- package/src/structures/ChannelSelectMenuComponent.js +2 -9
- package/src/structures/ChannelSelectMenuInteraction.js +3 -12
- package/src/structures/ChatInputCommandInteraction.js +3 -13
- package/src/structures/ClientApplication.js +20 -83
- package/src/structures/ClientPresence.js +5 -20
- package/src/structures/ClientUser.js +21 -118
- package/src/structures/CommandInteraction.js +21 -96
- package/src/structures/CommandInteractionOptionResolver.js +26 -147
- package/src/structures/Component.js +5 -21
- package/src/structures/ContextMenuCommandInteraction.js +4 -18
- package/src/structures/DMChannel.js +17 -52
- package/src/structures/DirectoryChannel.js +4 -16
- package/src/structures/Embed.js +21 -107
- package/src/structures/EmbedBuilder.js +4 -18
- package/src/structures/Emoji.js +12 -60
- package/src/structures/ForumChannel.js +30 -140
- package/src/structures/Guild.js +117 -697
- package/src/structures/GuildAuditLogs.js +7 -32
- package/src/structures/GuildAuditLogsEntry.js +27 -135
- package/src/structures/GuildBan.js +6 -26
- package/src/structures/GuildChannel.js +36 -188
- package/src/structures/GuildEmoji.js +13 -67
- package/src/structures/GuildMember.js +47 -270
- package/src/structures/GuildPreview.js +19 -84
- package/src/structures/GuildPreviewEmoji.js +3 -13
- package/src/structures/GuildScheduledEvent.js +46 -250
- package/src/structures/GuildTemplate.js +24 -108
- package/src/structures/Integration.js +25 -103
- package/src/structures/IntegrationApplication.js +8 -32
- package/src/structures/InteractionCollector.js +22 -113
- package/src/structures/InteractionResponse.js +11 -46
- package/src/structures/InteractionWebhook.js +8 -33
- package/src/structures/Invite.js +27 -131
- package/src/structures/InviteGuild.js +2 -8
- package/src/structures/InviteStageInstance.js +9 -39
- package/src/structures/MentionableSelectMenuBuilder.js +3 -14
- package/src/structures/MentionableSelectMenuComponent.js +1 -4
- package/src/structures/MentionableSelectMenuInteraction.js +5 -20
- package/src/structures/Message.js +85 -460
- package/src/structures/MessageCollector.js +14 -70
- package/src/structures/MessageComponentInteraction.js +14 -57
- package/src/structures/MessageContextMenuCommandInteraction.js +2 -9
- package/src/structures/MessageMentions.js +25 -136
- package/src/structures/MessagePayload.js +24 -94
- package/src/structures/MessageReaction.js +13 -51
- package/src/structures/ModalBuilder.js +3 -13
- package/src/structures/ModalSubmitFields.js +5 -22
- package/src/structures/ModalSubmitInteraction.js +17 -61
- package/src/structures/NewsChannel.js +2 -16
- package/src/structures/OAuth2Guild.js +3 -12
- package/src/structures/PartialGroupDMChannel.js +7 -27
- package/src/structures/PermissionOverwrites.js +20 -99
- package/src/structures/Presence.js +45 -190
- package/src/structures/ReactionCollector.js +20 -108
- package/src/structures/ReactionEmoji.js +2 -10
- package/src/structures/Role.js +39 -261
- package/src/structures/RoleSelectMenuBuilder.js +3 -13
- package/src/structures/RoleSelectMenuComponent.js +1 -4
- package/src/structures/RoleSelectMenuInteraction.js +3 -12
- package/src/structures/SelectMenuBuilder.js +1 -4
- package/src/structures/SelectMenuComponent.js +1 -4
- package/src/structures/SelectMenuInteraction.js +1 -4
- package/src/structures/SelectMenuOptionBuilder.js +1 -4
- package/src/structures/StageChannel.js +12 -84
- package/src/structures/StageInstance.js +16 -87
- package/src/structures/Sticker.js +25 -124
- package/src/structures/StickerPack.js +12 -52
- package/src/structures/StringSelectMenuBuilder.js +6 -29
- package/src/structures/StringSelectMenuComponent.js +2 -9
- package/src/structures/StringSelectMenuInteraction.js +2 -8
- package/src/structures/StringSelectMenuOptionBuilder.js +4 -18
- package/src/structures/Team.js +11 -52
- package/src/structures/TeamMember.js +7 -33
- package/src/structures/TextChannel.js +3 -14
- package/src/structures/TextInputBuilder.js +3 -13
- package/src/structures/TextInputComponent.js +3 -14
- package/src/structures/ThreadChannel.js +59 -305
- package/src/structures/ThreadMember.js +12 -55
- package/src/structures/Typing.js +8 -35
- package/src/structures/User.js +29 -151
- package/src/structures/UserContextMenuCommandInteraction.js +3 -14
- package/src/structures/UserSelectMenuBuilder.js +3 -13
- package/src/structures/UserSelectMenuComponent.js +1 -4
- package/src/structures/UserSelectMenuInteraction.js +4 -16
- package/src/structures/VoiceChannel.js +8 -67
- package/src/structures/VoiceRegion.js +6 -23
- package/src/structures/VoiceState.js +28 -140
- package/src/structures/Webhook.js +37 -227
- package/src/structures/WelcomeChannel.js +7 -29
- package/src/structures/WelcomeScreen.js +5 -20
- package/src/structures/Widget.js +9 -40
- package/src/structures/WidgetMember.js +15 -61
- package/src/structures/interfaces/Application.js +10 -49
- package/src/structures/interfaces/Collector.js +34 -155
- package/src/structures/interfaces/InteractionResponses.js +25 -164
- package/src/structures/interfaces/TextBasedChannel.js +37 -232
- package/src/util/APITypes.js +183 -456
- package/src/util/ActivityFlagsBitField.js +3 -15
- package/src/util/ApplicationFlagsBitField.js +3 -15
- package/src/util/BitField.js +17 -82
- package/src/util/ChannelFlagsBitField.js +7 -30
- package/src/util/Channels.js +5 -35
- package/src/util/Colors.js +3 -38
- package/src/util/Components.js +21 -75
- package/src/util/Constants.js +17 -144
- package/src/util/DataResolver.js +20 -77
- package/src/util/Events.js +3 -81
- package/src/util/Formatters.js +58 -305
- package/src/util/GuildMemberFlagsBitField.js +7 -30
- package/src/util/IntentsBitField.js +4 -23
- package/src/util/LimitedCollection.js +4 -21
- package/src/util/MessageFlagsBitField.js +5 -21
- package/src/util/Options.js +24 -137
- package/src/util/Partials.js +3 -30
- package/src/util/PermissionsBitField.js +12 -67
- package/src/util/ShardEvents.js +3 -15
- package/src/util/Status.js +3 -17
- package/src/util/Sweepers.js +35 -184
- package/src/util/SystemChannelFlagsBitField.js +7 -32
- package/src/util/ThreadMemberFlagsBitField.js +5 -21
- package/src/util/Transformers.js +2 -11
- package/src/util/UserFlagsBitField.js +5 -21
- package/src/util/Util.js +30 -169
- package/src/util/WebSocketShardEvents.js +3 -14
|
@@ -27,53 +27,32 @@ const MessageFlagsBitField = require('../util/MessageFlagsBitField');
|
|
|
27
27
|
const PermissionsBitField = require('../util/PermissionsBitField');
|
|
28
28
|
const { cleanContent, resolvePartialEmoji } = require('../util/Util');
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
* Represents a message on Discord.
|
|
32
|
-
* @extends {Base}
|
|
33
|
-
*/
|
|
30
|
+
|
|
34
31
|
class Message extends Base {
|
|
35
32
|
constructor(client, data) {
|
|
36
33
|
super(client);
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
* The id of the channel the message was sent in
|
|
40
|
-
* @type {Snowflake}
|
|
41
|
-
*/
|
|
35
|
+
|
|
42
36
|
this.channelId = data.channel_id;
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
* The id of the guild the message was sent in, if any
|
|
46
|
-
* @type {?Snowflake}
|
|
47
|
-
*/
|
|
38
|
+
|
|
48
39
|
this.guildId = data.guild_id ?? this.channel?.guild?.id ?? null;
|
|
49
40
|
|
|
50
41
|
this._patch(data);
|
|
51
42
|
}
|
|
52
43
|
|
|
53
44
|
_patch(data) {
|
|
54
|
-
|
|
55
|
-
* The message's id
|
|
56
|
-
* @type {Snowflake}
|
|
57
|
-
*/
|
|
45
|
+
|
|
58
46
|
this.id = data.id;
|
|
59
47
|
|
|
60
|
-
|
|
61
|
-
* The timestamp the message was sent at
|
|
62
|
-
* @type {number}
|
|
63
|
-
*/
|
|
48
|
+
|
|
64
49
|
this.createdTimestamp = DiscordSnowflake.timestampFrom(this.id);
|
|
65
50
|
|
|
66
51
|
if ('type' in data) {
|
|
67
|
-
|
|
68
|
-
* The type of the message
|
|
69
|
-
* @type {?MessageType}
|
|
70
|
-
*/
|
|
52
|
+
|
|
71
53
|
this.type = data.type;
|
|
72
54
|
|
|
73
|
-
|
|
74
|
-
* Whether or not this message was sent by Discord, not actually a user (e.g. pin notifications)
|
|
75
|
-
* @type {?boolean}
|
|
76
|
-
*/
|
|
55
|
+
|
|
77
56
|
this.system = !NonSystemMessageTypes.includes(this.type);
|
|
78
57
|
} else {
|
|
79
58
|
this.system ??= null;
|
|
@@ -81,90 +60,56 @@ class Message extends Base {
|
|
|
81
60
|
}
|
|
82
61
|
|
|
83
62
|
if ('content' in data) {
|
|
84
|
-
|
|
85
|
-
* The content of the message.
|
|
86
|
-
* <info>This property requires the {@link GatewayIntentBits.MessageContent} privileged intent
|
|
87
|
-
* in a guild for messages that do not mention the client.</info>
|
|
88
|
-
* @type {?string}
|
|
89
|
-
*/
|
|
63
|
+
|
|
90
64
|
this.content = data.content;
|
|
91
65
|
} else {
|
|
92
66
|
this.content ??= null;
|
|
93
67
|
}
|
|
94
68
|
|
|
95
69
|
if ('author' in data) {
|
|
96
|
-
|
|
97
|
-
* The author of the message
|
|
98
|
-
* @type {?User}
|
|
99
|
-
*/
|
|
70
|
+
|
|
100
71
|
this.author = this.client.users._add(data.author, !data.webhook_id);
|
|
101
72
|
} else {
|
|
102
73
|
this.author ??= null;
|
|
103
74
|
}
|
|
104
75
|
|
|
105
76
|
if ('pinned' in data) {
|
|
106
|
-
|
|
107
|
-
* Whether or not this message is pinned
|
|
108
|
-
* @type {?boolean}
|
|
109
|
-
*/
|
|
77
|
+
|
|
110
78
|
this.pinned = Boolean(data.pinned);
|
|
111
79
|
} else {
|
|
112
80
|
this.pinned ??= null;
|
|
113
81
|
}
|
|
114
82
|
|
|
115
83
|
if ('tts' in data) {
|
|
116
|
-
|
|
117
|
-
* Whether or not the message was Text-To-Speech
|
|
118
|
-
* @type {?boolean}
|
|
119
|
-
*/
|
|
84
|
+
|
|
120
85
|
this.tts = data.tts;
|
|
121
86
|
} else {
|
|
122
87
|
this.tts ??= null;
|
|
123
88
|
}
|
|
124
89
|
|
|
125
90
|
if ('nonce' in data) {
|
|
126
|
-
|
|
127
|
-
* A random number or string used for checking message delivery
|
|
128
|
-
* <warn>This is only received after the message was sent successfully, and
|
|
129
|
-
* lost if re-fetched</warn>
|
|
130
|
-
* @type {?string}
|
|
131
|
-
*/
|
|
91
|
+
|
|
132
92
|
this.nonce = data.nonce;
|
|
133
93
|
} else {
|
|
134
94
|
this.nonce ??= null;
|
|
135
95
|
}
|
|
136
96
|
|
|
137
97
|
if ('embeds' in data) {
|
|
138
|
-
|
|
139
|
-
* An array of embeds in the message - e.g. YouTube Player.
|
|
140
|
-
* <info>This property requires the {@link GatewayIntentBits.MessageContent} privileged intent
|
|
141
|
-
* in a guild for messages that do not mention the client.</info>
|
|
142
|
-
* @type {Embed[]}
|
|
143
|
-
*/
|
|
98
|
+
|
|
144
99
|
this.embeds = data.embeds.map(e => new Embed(e));
|
|
145
100
|
} else {
|
|
146
101
|
this.embeds = this.embeds?.slice() ?? [];
|
|
147
102
|
}
|
|
148
103
|
|
|
149
104
|
if ('components' in data) {
|
|
150
|
-
|
|
151
|
-
* An array of of action rows in the message.
|
|
152
|
-
* <info>This property requires the {@link GatewayIntentBits.MessageContent} privileged intent
|
|
153
|
-
* in a guild for messages that do not mention the client.</info>
|
|
154
|
-
* @type {ActionRow[]}
|
|
155
|
-
*/
|
|
105
|
+
|
|
156
106
|
this.components = data.components.map(c => createComponent(c));
|
|
157
107
|
} else {
|
|
158
108
|
this.components = this.components?.slice() ?? [];
|
|
159
109
|
}
|
|
160
110
|
|
|
161
111
|
if ('attachments' in data) {
|
|
162
|
-
|
|
163
|
-
* A collection of attachments in the message - e.g. Pictures - mapped by their ids.
|
|
164
|
-
* <info>This property requires the {@link GatewayIntentBits.MessageContent} privileged intent
|
|
165
|
-
* in a guild for messages that do not mention the client.</info>
|
|
166
|
-
* @type {Collection<Snowflake, Attachment>}
|
|
167
|
-
*/
|
|
112
|
+
|
|
168
113
|
this.attachments = new Collection();
|
|
169
114
|
if (data.attachments) {
|
|
170
115
|
for (const attachment of data.attachments) {
|
|
@@ -176,10 +121,7 @@ class Message extends Base {
|
|
|
176
121
|
}
|
|
177
122
|
|
|
178
123
|
if ('sticker_items' in data || 'stickers' in data) {
|
|
179
|
-
|
|
180
|
-
* A collection of stickers in the message
|
|
181
|
-
* @type {Collection<Snowflake, Sticker>}
|
|
182
|
-
*/
|
|
124
|
+
|
|
183
125
|
this.stickers = new Collection(
|
|
184
126
|
(data.sticker_items ?? data.stickers)?.map(s => [s.id, new Sticker(this.client, s)]),
|
|
185
127
|
);
|
|
@@ -188,31 +130,16 @@ class Message extends Base {
|
|
|
188
130
|
}
|
|
189
131
|
|
|
190
132
|
if ('position' in data) {
|
|
191
|
-
|
|
192
|
-
* A generally increasing integer (there may be gaps or duplicates) that represents
|
|
193
|
-
* the approximate position of the message in a thread.
|
|
194
|
-
* @type {?number}
|
|
195
|
-
*/
|
|
133
|
+
|
|
196
134
|
this.position = data.position;
|
|
197
135
|
} else {
|
|
198
136
|
this.position ??= null;
|
|
199
137
|
}
|
|
200
138
|
|
|
201
139
|
if ('role_subscription_data' in data) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
* @property {Snowflake} roleSubscriptionListingId The id of the SKU and listing the user is subscribed to
|
|
206
|
-
* @property {string} tierName The name of the tier the user is subscribed to
|
|
207
|
-
* @property {number} totalMonthsSubscribed The total number of months the user has been subscribed for
|
|
208
|
-
* @property {boolean} isRenewal Whether this notification is a renewal
|
|
209
|
-
*/
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* The data of the role subscription purchase or renewal.
|
|
213
|
-
* <info>This is present on {@link MessageType.RoleSubscriptionPurchase} messages.</info>
|
|
214
|
-
* @type {?RoleSubscriptionData}
|
|
215
|
-
*/
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
216
143
|
this.roleSubscriptionData = {
|
|
217
144
|
roleSubscriptionListingId: data.role_subscription_data.role_subscription_listing_id,
|
|
218
145
|
tierName: data.role_subscription_data.tier_name,
|
|
@@ -223,22 +150,16 @@ class Message extends Base {
|
|
|
223
150
|
this.roleSubscriptionData ??= null;
|
|
224
151
|
}
|
|
225
152
|
|
|
226
|
-
|
|
153
|
+
|
|
227
154
|
if (data.edited_timestamp) {
|
|
228
|
-
|
|
229
|
-
* The timestamp the message was last edited at (if applicable)
|
|
230
|
-
* @type {?number}
|
|
231
|
-
*/
|
|
155
|
+
|
|
232
156
|
this.editedTimestamp = Date.parse(data.edited_timestamp);
|
|
233
157
|
} else {
|
|
234
158
|
this.editedTimestamp ??= null;
|
|
235
159
|
}
|
|
236
160
|
|
|
237
161
|
if ('reactions' in data) {
|
|
238
|
-
|
|
239
|
-
* A manager of the reactions belonging to this message
|
|
240
|
-
* @type {ReactionManager}
|
|
241
|
-
*/
|
|
162
|
+
|
|
242
163
|
this.reactions = new ReactionManager(this);
|
|
243
164
|
if (data.reactions?.length > 0) {
|
|
244
165
|
for (const reaction of data.reactions) {
|
|
@@ -250,10 +171,7 @@ class Message extends Base {
|
|
|
250
171
|
}
|
|
251
172
|
|
|
252
173
|
if (!this.mentions) {
|
|
253
|
-
|
|
254
|
-
* All valid mentions that the message contains
|
|
255
|
-
* @type {MessageMentions}
|
|
256
|
-
*/
|
|
174
|
+
|
|
257
175
|
this.mentions = new Mentions(
|
|
258
176
|
this,
|
|
259
177
|
data.mentions,
|
|
@@ -274,40 +192,28 @@ class Message extends Base {
|
|
|
274
192
|
}
|
|
275
193
|
|
|
276
194
|
if ('webhook_id' in data) {
|
|
277
|
-
|
|
278
|
-
* The id of the webhook that sent the message, if applicable
|
|
279
|
-
* @type {?Snowflake}
|
|
280
|
-
*/
|
|
195
|
+
|
|
281
196
|
this.webhookId = data.webhook_id;
|
|
282
197
|
} else {
|
|
283
198
|
this.webhookId ??= null;
|
|
284
199
|
}
|
|
285
200
|
|
|
286
201
|
if ('application' in data) {
|
|
287
|
-
|
|
288
|
-
* Supplemental application information for group activities
|
|
289
|
-
* @type {?ClientApplication}
|
|
290
|
-
*/
|
|
202
|
+
|
|
291
203
|
this.groupActivityApplication = new ClientApplication(this.client, data.application);
|
|
292
204
|
} else {
|
|
293
205
|
this.groupActivityApplication ??= null;
|
|
294
206
|
}
|
|
295
207
|
|
|
296
208
|
if ('application_id' in data) {
|
|
297
|
-
|
|
298
|
-
* The id of the application of the interaction that sent this message, if any
|
|
299
|
-
* @type {?Snowflake}
|
|
300
|
-
*/
|
|
209
|
+
|
|
301
210
|
this.applicationId = data.application_id;
|
|
302
211
|
} else {
|
|
303
212
|
this.applicationId ??= null;
|
|
304
213
|
}
|
|
305
214
|
|
|
306
215
|
if ('activity' in data) {
|
|
307
|
-
|
|
308
|
-
* Group activity
|
|
309
|
-
* @type {?MessageActivity}
|
|
310
|
-
*/
|
|
216
|
+
|
|
311
217
|
this.activity = {
|
|
312
218
|
partyId: data.activity.party_id,
|
|
313
219
|
type: data.activity.type,
|
|
@@ -327,35 +233,16 @@ class Message extends Base {
|
|
|
327
233
|
}
|
|
328
234
|
|
|
329
235
|
if ('flags' in data) {
|
|
330
|
-
|
|
331
|
-
* Flags that are applied to the message
|
|
332
|
-
* @type {Readonly<MessageFlagsBitField>}
|
|
333
|
-
*/
|
|
236
|
+
|
|
334
237
|
this.flags = new MessageFlagsBitField(data.flags).freeze();
|
|
335
238
|
} else {
|
|
336
239
|
this.flags = new MessageFlagsBitField(this.flags).freeze();
|
|
337
240
|
}
|
|
338
241
|
|
|
339
|
-
|
|
340
|
-
* Reference data sent in a message that contains ids identifying the referenced message.
|
|
341
|
-
* This can be present in the following types of message:
|
|
342
|
-
* * Crossposted messages (`MessageFlags.Crossposted`)
|
|
343
|
-
* * {@link MessageType.ChannelFollowAdd}
|
|
344
|
-
* * {@link MessageType.ChannelPinnedMessage}
|
|
345
|
-
* * {@link MessageType.Reply}
|
|
346
|
-
* * {@link MessageType.ThreadStarterMessage}
|
|
347
|
-
* @see {@link https://discord.com/developers/docs/resources/channel#message-types}
|
|
348
|
-
* @typedef {Object} MessageReference
|
|
349
|
-
* @property {Snowflake} channelId The channel's id the message was referenced
|
|
350
|
-
* @property {?Snowflake} guildId The guild's id the message was referenced
|
|
351
|
-
* @property {?Snowflake} messageId The message's id that was referenced
|
|
352
|
-
*/
|
|
242
|
+
|
|
353
243
|
|
|
354
244
|
if ('message_reference' in data) {
|
|
355
|
-
|
|
356
|
-
* Message reference data
|
|
357
|
-
* @type {?MessageReference}
|
|
358
|
-
*/
|
|
245
|
+
|
|
359
246
|
this.reference = {
|
|
360
247
|
channelId: data.message_reference.channel_id,
|
|
361
248
|
guildId: data.message_reference.guild_id,
|
|
@@ -369,21 +256,10 @@ class Message extends Base {
|
|
|
369
256
|
this.channel?.messages._add({ guild_id: data.message_reference?.guild_id, ...data.referenced_message });
|
|
370
257
|
}
|
|
371
258
|
|
|
372
|
-
|
|
373
|
-
* Partial data of the interaction that a message is a reply to
|
|
374
|
-
* @typedef {Object} MessageInteraction
|
|
375
|
-
* @property {Snowflake} id The interaction's id
|
|
376
|
-
* @property {InteractionType} type The type of the interaction
|
|
377
|
-
* @property {string} commandName The name of the interaction's application command,
|
|
378
|
-
* as well as the subcommand and subcommand group, where applicable
|
|
379
|
-
* @property {User} user The user that invoked the interaction
|
|
380
|
-
*/
|
|
259
|
+
|
|
381
260
|
|
|
382
261
|
if (data.interaction) {
|
|
383
|
-
|
|
384
|
-
* Partial data of the interaction that this message is a reply to
|
|
385
|
-
* @type {?MessageInteraction}
|
|
386
|
-
*/
|
|
262
|
+
|
|
387
263
|
this.interaction = {
|
|
388
264
|
id: data.interaction.id,
|
|
389
265
|
type: data.interaction.type,
|
|
@@ -395,134 +271,65 @@ class Message extends Base {
|
|
|
395
271
|
}
|
|
396
272
|
}
|
|
397
273
|
|
|
398
|
-
|
|
399
|
-
* The channel that the message was sent in
|
|
400
|
-
* @type {TextBasedChannels}
|
|
401
|
-
* @readonly
|
|
402
|
-
*/
|
|
274
|
+
|
|
403
275
|
get channel() {
|
|
404
276
|
return this.client.channels.resolve(this.channelId);
|
|
405
277
|
}
|
|
406
278
|
|
|
407
|
-
|
|
408
|
-
* Whether or not this message is a partial
|
|
409
|
-
* @type {boolean}
|
|
410
|
-
* @readonly
|
|
411
|
-
*/
|
|
279
|
+
|
|
412
280
|
get partial() {
|
|
413
281
|
return typeof this.content !== 'string' || !this.author;
|
|
414
282
|
}
|
|
415
283
|
|
|
416
|
-
|
|
417
|
-
* Represents the author of the message as a guild member.
|
|
418
|
-
* Only available if the message comes from a guild where the author is still a member
|
|
419
|
-
* @type {?GuildMember}
|
|
420
|
-
* @readonly
|
|
421
|
-
*/
|
|
284
|
+
|
|
422
285
|
get member() {
|
|
423
286
|
return this.guild?.members.resolve(this.author) ?? null;
|
|
424
287
|
}
|
|
425
288
|
|
|
426
|
-
|
|
427
|
-
* The time the message was sent at
|
|
428
|
-
* @type {Date}
|
|
429
|
-
* @readonly
|
|
430
|
-
*/
|
|
289
|
+
|
|
431
290
|
get createdAt() {
|
|
432
291
|
return new Date(this.createdTimestamp);
|
|
433
292
|
}
|
|
434
293
|
|
|
435
|
-
|
|
436
|
-
* The time the message was last edited at (if applicable)
|
|
437
|
-
* @type {?Date}
|
|
438
|
-
* @readonly
|
|
439
|
-
*/
|
|
294
|
+
|
|
440
295
|
get editedAt() {
|
|
441
296
|
return this.editedTimestamp && new Date(this.editedTimestamp);
|
|
442
297
|
}
|
|
443
298
|
|
|
444
|
-
|
|
445
|
-
* The guild the message was sent in (if in a guild channel)
|
|
446
|
-
* @type {?Guild}
|
|
447
|
-
* @readonly
|
|
448
|
-
*/
|
|
299
|
+
|
|
449
300
|
get guild() {
|
|
450
301
|
return this.client.guilds.resolve(this.guildId) ?? this.channel?.guild ?? null;
|
|
451
302
|
}
|
|
452
303
|
|
|
453
|
-
|
|
454
|
-
* Whether this message has a thread associated with it
|
|
455
|
-
* @type {boolean}
|
|
456
|
-
* @readonly
|
|
457
|
-
*/
|
|
304
|
+
|
|
458
305
|
get hasThread() {
|
|
459
306
|
return this.flags.has(MessageFlags.HasThread);
|
|
460
307
|
}
|
|
461
308
|
|
|
462
|
-
|
|
463
|
-
* The thread started by this message
|
|
464
|
-
* <info>This property is not suitable for checking whether a message has a thread,
|
|
465
|
-
* use {@link Message#hasThread} instead.</info>
|
|
466
|
-
* @type {?ThreadChannel}
|
|
467
|
-
* @readonly
|
|
468
|
-
*/
|
|
309
|
+
|
|
469
310
|
get thread() {
|
|
470
311
|
return this.channel?.threads?.resolve(this.id) ?? null;
|
|
471
312
|
}
|
|
472
313
|
|
|
473
|
-
|
|
474
|
-
* The URL to jump to this message
|
|
475
|
-
* @type {string}
|
|
476
|
-
* @readonly
|
|
477
|
-
*/
|
|
314
|
+
|
|
478
315
|
get url() {
|
|
479
316
|
return this.inGuild() ? messageLink(this.channelId, this.id, this.guildId) : messageLink(this.channelId, this.id);
|
|
480
317
|
}
|
|
481
318
|
|
|
482
|
-
|
|
483
|
-
* The message contents with all mentions replaced by the equivalent text.
|
|
484
|
-
* If mentions cannot be resolved to a name, the relevant mention in the message content will not be converted.
|
|
485
|
-
* @type {?string}
|
|
486
|
-
* @readonly
|
|
487
|
-
*/
|
|
319
|
+
|
|
488
320
|
get cleanContent() {
|
|
489
|
-
|
|
321
|
+
|
|
490
322
|
return this.content != null ? cleanContent(this.content, this.channel) : null;
|
|
491
323
|
}
|
|
492
324
|
|
|
493
|
-
|
|
494
|
-
* Creates a reaction collector.
|
|
495
|
-
* @param {ReactionCollectorOptions} [options={}] Options to send to the collector
|
|
496
|
-
* @returns {ReactionCollector}
|
|
497
|
-
* @example
|
|
498
|
-
* // Create a reaction collector
|
|
499
|
-
* const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someId';
|
|
500
|
-
* const collector = message.createReactionCollector({ filter, time: 15_000 });
|
|
501
|
-
* collector.on('collect', r => console.log(`Collected ${r.emoji.name}`));
|
|
502
|
-
* collector.on('end', collected => console.log(`Collected ${collected.size} items`));
|
|
503
|
-
*/
|
|
325
|
+
|
|
504
326
|
createReactionCollector(options = {}) {
|
|
505
327
|
return new ReactionCollector(this, options);
|
|
506
328
|
}
|
|
507
329
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
* @property {string[]} [errors] Stop/end reasons that cause the promise to reject
|
|
512
|
-
*/
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Similar to createReactionCollector but in promise form.
|
|
516
|
-
* Resolves with a collection of reactions that pass the specified filter.
|
|
517
|
-
* @param {AwaitReactionsOptions} [options={}] Optional options to pass to the internal collector
|
|
518
|
-
* @returns {Promise<Collection<string | Snowflake, MessageReaction>>}
|
|
519
|
-
* @example
|
|
520
|
-
* // Create a reaction collector
|
|
521
|
-
* const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someId'
|
|
522
|
-
* message.awaitReactions({ filter, time: 15_000 })
|
|
523
|
-
* .then(collected => console.log(`Collected ${collected.size} reactions`))
|
|
524
|
-
* .catch(console.error);
|
|
525
|
-
*/
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
526
333
|
awaitReactions(options = {}) {
|
|
527
334
|
return new Promise((resolve, reject) => {
|
|
528
335
|
const collector = this.createReactionCollector(options);
|
|
@@ -533,25 +340,9 @@ class Message extends Base {
|
|
|
533
340
|
});
|
|
534
341
|
}
|
|
535
342
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
* @property {number} [max] The maximum total amount of interactions to collect
|
|
540
|
-
* @property {number} [maxComponents] The maximum number of components to collect
|
|
541
|
-
* @property {number} [maxUsers] The maximum number of users to interact
|
|
542
|
-
*/
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Creates a message component interaction collector.
|
|
546
|
-
* @param {MessageComponentCollectorOptions} [options={}] Options to send to the collector
|
|
547
|
-
* @returns {InteractionCollector}
|
|
548
|
-
* @example
|
|
549
|
-
* // Create a message component interaction collector
|
|
550
|
-
* const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
|
|
551
|
-
* const collector = message.createMessageComponentCollector({ filter, time: 15_000 });
|
|
552
|
-
* collector.on('collect', i => console.log(`Collected ${i.customId}`));
|
|
553
|
-
* collector.on('end', collected => console.log(`Collected ${collected.size} items`));
|
|
554
|
-
*/
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
555
346
|
createMessageComponentCollector(options = {}) {
|
|
556
347
|
return new InteractionCollector(this.client, {
|
|
557
348
|
...options,
|
|
@@ -560,29 +351,9 @@ class Message extends Base {
|
|
|
560
351
|
});
|
|
561
352
|
}
|
|
562
353
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
* @property {CollectorFilter} [filter] The filter applied to this collector
|
|
567
|
-
* @property {number} [time] Time to wait for an interaction before rejecting
|
|
568
|
-
* @property {ComponentType} [componentType] The type of component interaction to collect
|
|
569
|
-
* @property {number} [idle] Time to wait without another message component interaction before ending the collector
|
|
570
|
-
* @property {boolean} [dispose] Whether to remove the message component interaction after collecting
|
|
571
|
-
* @property {InteractionResponse} [interactionResponse] The interaction response to collect interactions from
|
|
572
|
-
*/
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* Collects a single component interaction that passes the filter.
|
|
576
|
-
* The Promise will reject if the time expires.
|
|
577
|
-
* @param {AwaitMessageComponentOptions} [options={}] Options to pass to the internal collector
|
|
578
|
-
* @returns {Promise<MessageComponentInteraction>}
|
|
579
|
-
* @example
|
|
580
|
-
* // Collect a message component interaction
|
|
581
|
-
* const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
|
|
582
|
-
* message.awaitMessageComponent({ filter, time: 15_000 })
|
|
583
|
-
* .then(interaction => console.log(`${interaction.customId} was clicked!`))
|
|
584
|
-
* .catch(console.error);
|
|
585
|
-
*/
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
586
357
|
awaitMessageComponent(options = {}) {
|
|
587
358
|
const _options = { ...options, max: 1 };
|
|
588
359
|
return new Promise((resolve, reject) => {
|
|
@@ -595,16 +366,12 @@ class Message extends Base {
|
|
|
595
366
|
});
|
|
596
367
|
}
|
|
597
368
|
|
|
598
|
-
|
|
599
|
-
* Whether the message is editable by the client user
|
|
600
|
-
* @type {boolean}
|
|
601
|
-
* @readonly
|
|
602
|
-
*/
|
|
369
|
+
|
|
603
370
|
get editable() {
|
|
604
371
|
const precheck = Boolean(this.author.id === this.client.user.id && (!this.guild || this.channel?.viewable));
|
|
605
372
|
|
|
606
|
-
|
|
607
|
-
|
|
373
|
+
|
|
374
|
+
|
|
608
375
|
if (this.channel?.isThread()) {
|
|
609
376
|
if (this.channel.archived) return false;
|
|
610
377
|
if (this.channel.locked) {
|
|
@@ -616,42 +383,31 @@ class Message extends Base {
|
|
|
616
383
|
return precheck;
|
|
617
384
|
}
|
|
618
385
|
|
|
619
|
-
|
|
620
|
-
* Whether the message is deletable by the client user
|
|
621
|
-
* @type {boolean}
|
|
622
|
-
* @readonly
|
|
623
|
-
*/
|
|
386
|
+
|
|
624
387
|
get deletable() {
|
|
625
388
|
if (!DeletableMessageTypes.includes(this.type)) return false;
|
|
626
389
|
|
|
627
390
|
if (!this.guild) {
|
|
628
391
|
return this.author.id === this.client.user.id;
|
|
629
392
|
}
|
|
630
|
-
|
|
393
|
+
|
|
631
394
|
if (!this.channel?.viewable) {
|
|
632
395
|
return false;
|
|
633
396
|
}
|
|
634
397
|
|
|
635
398
|
const permissions = this.channel?.permissionsFor(this.client.user);
|
|
636
399
|
if (!permissions) return false;
|
|
637
|
-
|
|
400
|
+
|
|
638
401
|
if (permissions.has(PermissionFlagsBits.Administrator, false)) return true;
|
|
639
402
|
|
|
640
|
-
|
|
403
|
+
|
|
641
404
|
return (
|
|
642
405
|
(this.type !== MessageType.AutoModerationAction && this.author.id === this.client.user.id) ||
|
|
643
406
|
(permissions.has(PermissionFlagsBits.ManageMessages, false) && !this.guild.members.me.isCommunicationDisabled())
|
|
644
407
|
);
|
|
645
408
|
}
|
|
646
409
|
|
|
647
|
-
|
|
648
|
-
* Whether the message is bulk deletable by the client user
|
|
649
|
-
* @type {boolean}
|
|
650
|
-
* @readonly
|
|
651
|
-
* @example
|
|
652
|
-
* // Filter for bulk deletable messages
|
|
653
|
-
* channel.bulkDelete(messages.filter(message => message.bulkDeletable));
|
|
654
|
-
*/
|
|
410
|
+
|
|
655
411
|
get bulkDeletable() {
|
|
656
412
|
return (
|
|
657
413
|
(this.inGuild() &&
|
|
@@ -662,11 +418,7 @@ class Message extends Base {
|
|
|
662
418
|
);
|
|
663
419
|
}
|
|
664
420
|
|
|
665
|
-
|
|
666
|
-
* Whether the message is pinnable by the client user
|
|
667
|
-
* @type {boolean}
|
|
668
|
-
* @readonly
|
|
669
|
-
*/
|
|
421
|
+
|
|
670
422
|
get pinnable() {
|
|
671
423
|
const { channel } = this;
|
|
672
424
|
return Boolean(
|
|
@@ -677,10 +429,7 @@ class Message extends Base {
|
|
|
677
429
|
);
|
|
678
430
|
}
|
|
679
431
|
|
|
680
|
-
|
|
681
|
-
* Fetches the Message this crosspost/reply/pin-add references, if available to the client
|
|
682
|
-
* @returns {Promise<Message>}
|
|
683
|
-
*/
|
|
432
|
+
|
|
684
433
|
async fetchReference() {
|
|
685
434
|
if (!this.reference) throw new DiscordjsError(ErrorCodes.MessageReferenceMissing);
|
|
686
435
|
const { channelId, messageId } = this.reference;
|
|
@@ -690,11 +439,7 @@ class Message extends Base {
|
|
|
690
439
|
return message;
|
|
691
440
|
}
|
|
692
441
|
|
|
693
|
-
|
|
694
|
-
* Whether the message is crosspostable by the client user
|
|
695
|
-
* @type {boolean}
|
|
696
|
-
* @readonly
|
|
697
|
-
*/
|
|
442
|
+
|
|
698
443
|
get crosspostable() {
|
|
699
444
|
const bitfield =
|
|
700
445
|
PermissionFlagsBits.SendMessages |
|
|
@@ -709,84 +454,33 @@ class Message extends Base {
|
|
|
709
454
|
);
|
|
710
455
|
}
|
|
711
456
|
|
|
712
|
-
|
|
713
|
-
* Edits the content of the message.
|
|
714
|
-
* @param {string|MessagePayload|MessageEditOptions} options The options to provide
|
|
715
|
-
* @returns {Promise<Message>}
|
|
716
|
-
* @example
|
|
717
|
-
* // Update the content of a message
|
|
718
|
-
* message.edit('This is my new content!')
|
|
719
|
-
* .then(msg => console.log(`Updated the content of a message to ${msg.content}`))
|
|
720
|
-
* .catch(console.error);
|
|
721
|
-
*/
|
|
457
|
+
|
|
722
458
|
edit(options) {
|
|
723
459
|
if (!this.channel) return Promise.reject(new DiscordjsError(ErrorCodes.ChannelNotCached));
|
|
724
460
|
return this.channel.messages.edit(this, options);
|
|
725
461
|
}
|
|
726
462
|
|
|
727
|
-
|
|
728
|
-
* Publishes a message in an announcement channel to all channels following it.
|
|
729
|
-
* @returns {Promise<Message>}
|
|
730
|
-
* @example
|
|
731
|
-
* // Crosspost a message
|
|
732
|
-
* if (message.channel.type === ChannelType.GuildAnnouncement) {
|
|
733
|
-
* message.crosspost()
|
|
734
|
-
* .then(() => console.log('Crossposted message'))
|
|
735
|
-
* .catch(console.error);
|
|
736
|
-
* }
|
|
737
|
-
*/
|
|
463
|
+
|
|
738
464
|
crosspost() {
|
|
739
465
|
if (!this.channel) return Promise.reject(new DiscordjsError(ErrorCodes.ChannelNotCached));
|
|
740
466
|
return this.channel.messages.crosspost(this.id);
|
|
741
467
|
}
|
|
742
468
|
|
|
743
|
-
|
|
744
|
-
* Pins this message to the channel's pinned messages.
|
|
745
|
-
* @param {string} [reason] Reason for pinning
|
|
746
|
-
* @returns {Promise<Message>}
|
|
747
|
-
* @example
|
|
748
|
-
* // Pin a message
|
|
749
|
-
* message.pin()
|
|
750
|
-
* .then(console.log)
|
|
751
|
-
* .catch(console.error)
|
|
752
|
-
*/
|
|
469
|
+
|
|
753
470
|
async pin(reason) {
|
|
754
471
|
if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
|
|
755
472
|
await this.channel.messages.pin(this.id, reason);
|
|
756
473
|
return this;
|
|
757
474
|
}
|
|
758
475
|
|
|
759
|
-
|
|
760
|
-
* Unpins this message from the channel's pinned messages.
|
|
761
|
-
* @param {string} [reason] Reason for unpinning
|
|
762
|
-
* @returns {Promise<Message>}
|
|
763
|
-
* @example
|
|
764
|
-
* // Unpin a message
|
|
765
|
-
* message.unpin()
|
|
766
|
-
* .then(console.log)
|
|
767
|
-
* .catch(console.error)
|
|
768
|
-
*/
|
|
476
|
+
|
|
769
477
|
async unpin(reason) {
|
|
770
478
|
if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
|
|
771
479
|
await this.channel.messages.unpin(this.id, reason);
|
|
772
480
|
return this;
|
|
773
481
|
}
|
|
774
482
|
|
|
775
|
-
|
|
776
|
-
* Adds a reaction to the message.
|
|
777
|
-
* @param {EmojiIdentifierResolvable} emoji The emoji to react with
|
|
778
|
-
* @returns {Promise<MessageReaction>}
|
|
779
|
-
* @example
|
|
780
|
-
* // React to a message with a unicode emoji
|
|
781
|
-
* message.react('🤔')
|
|
782
|
-
* .then(console.log)
|
|
783
|
-
* .catch(console.error);
|
|
784
|
-
* @example
|
|
785
|
-
* // React to a message with a custom emoji
|
|
786
|
-
* message.react(message.guild.emojis.cache.get('123456789012345678'))
|
|
787
|
-
* .then(console.log)
|
|
788
|
-
* .catch(console.error);
|
|
789
|
-
*/
|
|
483
|
+
|
|
790
484
|
async react(emoji) {
|
|
791
485
|
if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
|
|
792
486
|
await this.channel.messages.react(this.id, emoji);
|
|
@@ -802,38 +496,16 @@ class Message extends Base {
|
|
|
802
496
|
).reaction;
|
|
803
497
|
}
|
|
804
498
|
|
|
805
|
-
|
|
806
|
-
* Deletes the message.
|
|
807
|
-
* @returns {Promise<Message>}
|
|
808
|
-
* @example
|
|
809
|
-
* // Delete a message
|
|
810
|
-
* message.delete()
|
|
811
|
-
* .then(msg => console.log(`Deleted message from ${msg.author.username}`))
|
|
812
|
-
* .catch(console.error);
|
|
813
|
-
*/
|
|
499
|
+
|
|
814
500
|
async delete() {
|
|
815
501
|
if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
|
|
816
502
|
await this.channel.messages.delete(this.id);
|
|
817
503
|
return this;
|
|
818
504
|
}
|
|
819
505
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
* @property {boolean} [failIfNotExists=this.client.options.failIfNotExists] Whether to error if the referenced
|
|
824
|
-
* message does not exist (creates a standard message in this case when false)
|
|
825
|
-
*/
|
|
826
|
-
|
|
827
|
-
/**
|
|
828
|
-
* Send an inline reply to this message.
|
|
829
|
-
* @param {string|MessagePayload|MessageReplyOptions} options The options to provide
|
|
830
|
-
* @returns {Promise<Message>}
|
|
831
|
-
* @example
|
|
832
|
-
* // Reply to a message
|
|
833
|
-
* message.reply('This is a reply!')
|
|
834
|
-
* .then(() => console.log(`Replied to message "${message.content}"`))
|
|
835
|
-
* .catch(console.error);
|
|
836
|
-
*/
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
837
509
|
reply(options) {
|
|
838
510
|
if (!this.channel) return Promise.reject(new DiscordjsError(ErrorCodes.ChannelNotCached));
|
|
839
511
|
let data;
|
|
@@ -851,22 +523,9 @@ class Message extends Base {
|
|
|
851
523
|
return this.channel.send(data);
|
|
852
524
|
}
|
|
853
525
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
* @property {string} name The name of the new thread
|
|
858
|
-
* @property {ThreadAutoArchiveDuration} [autoArchiveDuration=this.channel.defaultAutoArchiveDuration] The amount of
|
|
859
|
-
* time after which the thread should automatically archive in case of no recent activity
|
|
860
|
-
* @property {string} [reason] Reason for creating the thread
|
|
861
|
-
* @property {number} [rateLimitPerUser] The rate limit per user (slowmode) for the thread in seconds
|
|
862
|
-
*/
|
|
863
|
-
|
|
864
|
-
/**
|
|
865
|
-
* Create a new public thread from this message
|
|
866
|
-
* @see GuildTextThreadManager#create
|
|
867
|
-
* @param {StartThreadOptions} [options] Options for starting a thread on this message
|
|
868
|
-
* @returns {Promise<ThreadChannel>}
|
|
869
|
-
*/
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
870
529
|
startThread(options = {}) {
|
|
871
530
|
if (!this.channel) return Promise.reject(new DiscordjsError(ErrorCodes.ChannelNotCached));
|
|
872
531
|
if (![ChannelType.GuildText, ChannelType.GuildAnnouncement].includes(this.channel.type)) {
|
|
@@ -876,31 +535,20 @@ class Message extends Base {
|
|
|
876
535
|
return this.channel.threads.create({ ...options, startMessage: this });
|
|
877
536
|
}
|
|
878
537
|
|
|
879
|
-
|
|
880
|
-
* Fetch this message.
|
|
881
|
-
* @param {boolean} [force=true] Whether to skip the cache check and request the API
|
|
882
|
-
* @returns {Promise<Message>}
|
|
883
|
-
*/
|
|
538
|
+
|
|
884
539
|
fetch(force = true) {
|
|
885
540
|
if (!this.channel) return Promise.reject(new DiscordjsError(ErrorCodes.ChannelNotCached));
|
|
886
541
|
return this.channel.messages.fetch({ message: this.id, force });
|
|
887
542
|
}
|
|
888
543
|
|
|
889
|
-
|
|
890
|
-
* Fetches the webhook used to create this message.
|
|
891
|
-
* @returns {Promise<?Webhook>}
|
|
892
|
-
*/
|
|
544
|
+
|
|
893
545
|
fetchWebhook() {
|
|
894
546
|
if (!this.webhookId) return Promise.reject(new DiscordjsError(ErrorCodes.WebhookMessage));
|
|
895
547
|
if (this.webhookId === this.applicationId) return Promise.reject(new DiscordjsError(ErrorCodes.WebhookApplication));
|
|
896
548
|
return this.client.fetchWebhook(this.webhookId);
|
|
897
549
|
}
|
|
898
550
|
|
|
899
|
-
|
|
900
|
-
* Suppresses or unsuppresses embeds on a message.
|
|
901
|
-
* @param {boolean} [suppress=true] If the embeds should be suppressed or not
|
|
902
|
-
* @returns {Promise<Message>}
|
|
903
|
-
*/
|
|
551
|
+
|
|
904
552
|
suppressEmbeds(suppress = true) {
|
|
905
553
|
const flags = new MessageFlagsBitField(this.flags.bitfield);
|
|
906
554
|
|
|
@@ -913,31 +561,17 @@ class Message extends Base {
|
|
|
913
561
|
return this.edit({ flags });
|
|
914
562
|
}
|
|
915
563
|
|
|
916
|
-
|
|
917
|
-
* Removes the attachments from this message.
|
|
918
|
-
* @returns {Promise<Message>}
|
|
919
|
-
*/
|
|
564
|
+
|
|
920
565
|
removeAttachments() {
|
|
921
566
|
return this.edit({ attachments: [] });
|
|
922
567
|
}
|
|
923
568
|
|
|
924
|
-
|
|
925
|
-
* Resolves a component by a custom id.
|
|
926
|
-
* @param {string} customId The custom id to resolve against
|
|
927
|
-
* @returns {?MessageActionRowComponent}
|
|
928
|
-
*/
|
|
569
|
+
|
|
929
570
|
resolveComponent(customId) {
|
|
930
571
|
return this.components.flatMap(row => row.components).find(component => component.customId === customId) ?? null;
|
|
931
572
|
}
|
|
932
573
|
|
|
933
|
-
|
|
934
|
-
* Used mainly internally. Whether two messages are identical in properties. If you want to compare messages
|
|
935
|
-
* without checking all the properties, use `message.id === message2.id`, which is much more efficient. This
|
|
936
|
-
* method allows you to see if there are differences in content, embeds, attachments, nonce and tts properties.
|
|
937
|
-
* @param {Message} message The message to compare it to
|
|
938
|
-
* @param {APIMessage} rawData Raw data passed through the WebSocket about this message
|
|
939
|
-
* @returns {boolean}
|
|
940
|
-
*/
|
|
574
|
+
|
|
941
575
|
equals(message, rawData) {
|
|
942
576
|
if (!message) return false;
|
|
943
577
|
const embedUpdate = !message.author && !message.attachments;
|
|
@@ -962,21 +596,12 @@ class Message extends Base {
|
|
|
962
596
|
return equal;
|
|
963
597
|
}
|
|
964
598
|
|
|
965
|
-
|
|
966
|
-
* Whether this message is from a guild.
|
|
967
|
-
* @returns {boolean}
|
|
968
|
-
*/
|
|
599
|
+
|
|
969
600
|
inGuild() {
|
|
970
601
|
return Boolean(this.guildId);
|
|
971
602
|
}
|
|
972
603
|
|
|
973
|
-
|
|
974
|
-
* When concatenated with a string, this automatically concatenates the message's content instead of the object.
|
|
975
|
-
* @returns {string}
|
|
976
|
-
* @example
|
|
977
|
-
* // Logs: Message: This is a message!
|
|
978
|
-
* console.log(`Message: ${message}`);
|
|
979
|
-
*/
|
|
604
|
+
|
|
980
605
|
toString() {
|
|
981
606
|
return this.content;
|
|
982
607
|
}
|