@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
|
@@ -10,10 +10,7 @@ const { Role } = require('../structures/Role');
|
|
|
10
10
|
|
|
11
11
|
let cacheWarningEmitted = false;
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
* Manages API methods for guild channel permission overwrites and stores their cache.
|
|
15
|
-
* @extends {CachedManager}
|
|
16
|
-
*/
|
|
13
|
+
|
|
17
14
|
class PermissionOverwriteManager extends CachedManager {
|
|
18
15
|
constructor(channel, iterable) {
|
|
19
16
|
super(channel.client, PermissionOverwrites);
|
|
@@ -25,10 +22,7 @@ class PermissionOverwriteManager extends CachedManager {
|
|
|
25
22
|
);
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
* The channel of the permission overwrite this manager belongs to
|
|
30
|
-
* @type {GuildChannel}
|
|
31
|
-
*/
|
|
25
|
+
|
|
32
26
|
this.channel = channel;
|
|
33
27
|
|
|
34
28
|
if (iterable) {
|
|
@@ -38,30 +32,13 @@ class PermissionOverwriteManager extends CachedManager {
|
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
* The cache of this Manager
|
|
43
|
-
* @type {Collection<Snowflake, PermissionOverwrites>}
|
|
44
|
-
* @name PermissionOverwriteManager#cache
|
|
45
|
-
*/
|
|
35
|
+
|
|
46
36
|
|
|
47
37
|
_add(data, cache) {
|
|
48
38
|
return super._add(data, cache, { extras: [this.channel] });
|
|
49
39
|
}
|
|
50
40
|
|
|
51
|
-
|
|
52
|
-
* Replaces the permission overwrites in this channel.
|
|
53
|
-
* @param {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} overwrites
|
|
54
|
-
* Permission overwrites the channel gets updated with
|
|
55
|
-
* @param {string} [reason] Reason for updating the channel overwrites
|
|
56
|
-
* @returns {Promise<GuildChannel>}
|
|
57
|
-
* @example
|
|
58
|
-
* message.channel.permissionOverwrites.set([
|
|
59
|
-
* {
|
|
60
|
-
* id: message.author.id,
|
|
61
|
-
* deny: [PermissionsFlagsBit.ViewChannel],
|
|
62
|
-
* },
|
|
63
|
-
* ], 'Needed to change permissions');
|
|
64
|
-
*/
|
|
41
|
+
|
|
65
42
|
set(overwrites, reason) {
|
|
66
43
|
if (!Array.isArray(overwrites) && !(overwrites instanceof Collection)) {
|
|
67
44
|
return Promise.reject(
|
|
@@ -76,23 +53,9 @@ class PermissionOverwriteManager extends CachedManager {
|
|
|
76
53
|
return this.channel.edit({ permissionOverwrites: overwrites, reason });
|
|
77
54
|
}
|
|
78
55
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* @property {string} [reason] The reason for creating/editing this overwrite
|
|
83
|
-
* @property {OverwriteType} [type] The type of overwrite. Use this to bypass automatic resolution of `type`
|
|
84
|
-
* that results in an error for an uncached structure
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Creates or edits permission overwrites for a user or role in this channel.
|
|
89
|
-
* @param {RoleResolvable|UserResolvable} userOrRole The user or role to update
|
|
90
|
-
* @param {PermissionOverwriteOptions} options The options for the update
|
|
91
|
-
* @param {GuildChannelOverwriteOptions} [overwriteOptions] The extra information for the update
|
|
92
|
-
* @param {PermissionOverwrites} [existing] The existing overwrites to merge with this update
|
|
93
|
-
* @returns {Promise<GuildChannel>}
|
|
94
|
-
* @private
|
|
95
|
-
*/
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
96
59
|
async upsert(userOrRole, options, overwriteOptions = {}, existing) {
|
|
97
60
|
let userOrRoleId = this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole);
|
|
98
61
|
let { type, reason } = overwriteOptions;
|
|
@@ -111,38 +74,12 @@ class PermissionOverwriteManager extends CachedManager {
|
|
|
111
74
|
return this.channel;
|
|
112
75
|
}
|
|
113
76
|
|
|
114
|
-
|
|
115
|
-
* Creates permission overwrites for a user or role in this channel, or replaces them if already present.
|
|
116
|
-
* @param {RoleResolvable|UserResolvable} userOrRole The user or role to update
|
|
117
|
-
* @param {PermissionOverwriteOptions} options The options for the update
|
|
118
|
-
* @param {GuildChannelOverwriteOptions} [overwriteOptions] The extra information for the update
|
|
119
|
-
* @returns {Promise<GuildChannel>}
|
|
120
|
-
* @example
|
|
121
|
-
* // Create or Replace permission overwrites for a message author
|
|
122
|
-
* message.channel.permissionOverwrites.create(message.author, {
|
|
123
|
-
* SendMessages: false
|
|
124
|
-
* })
|
|
125
|
-
* .then(channel => console.log(channel.permissionOverwrites.cache.get(message.author.id)))
|
|
126
|
-
* .catch(console.error);
|
|
127
|
-
*/
|
|
77
|
+
|
|
128
78
|
create(userOrRole, options, overwriteOptions) {
|
|
129
79
|
return this.upsert(userOrRole, options, overwriteOptions);
|
|
130
80
|
}
|
|
131
81
|
|
|
132
|
-
|
|
133
|
-
* Edits permission overwrites for a user or role in this channel, or creates an entry if not already present.
|
|
134
|
-
* @param {RoleResolvable|UserResolvable} userOrRole The user or role to update
|
|
135
|
-
* @param {PermissionOverwriteOptions} options The options for the update
|
|
136
|
-
* @param {GuildChannelOverwriteOptions} [overwriteOptions] The extra information for the update
|
|
137
|
-
* @returns {Promise<GuildChannel>}
|
|
138
|
-
* @example
|
|
139
|
-
* // Edit or Create permission overwrites for a message author
|
|
140
|
-
* message.channel.permissionOverwrites.edit(message.author, {
|
|
141
|
-
* SendMessages: false
|
|
142
|
-
* })
|
|
143
|
-
* .then(channel => console.log(channel.permissionOverwrites.cache.get(message.author.id)))
|
|
144
|
-
* .catch(console.error);
|
|
145
|
-
*/
|
|
82
|
+
|
|
146
83
|
edit(userOrRole, options, overwriteOptions) {
|
|
147
84
|
const existing = this.cache.get(
|
|
148
85
|
this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole),
|
|
@@ -150,12 +87,7 @@ class PermissionOverwriteManager extends CachedManager {
|
|
|
150
87
|
return this.upsert(userOrRole, options, overwriteOptions, existing);
|
|
151
88
|
}
|
|
152
89
|
|
|
153
|
-
|
|
154
|
-
* Deletes permission overwrites for a user or role in this channel.
|
|
155
|
-
* @param {UserResolvable|RoleResolvable} userOrRole The user or role to delete
|
|
156
|
-
* @param {string} [reason] The reason for deleting the overwrite
|
|
157
|
-
* @returns {Promise<GuildChannel>}
|
|
158
|
-
*/
|
|
90
|
+
|
|
159
91
|
async delete(userOrRole, reason) {
|
|
160
92
|
const userOrRoleId = this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole);
|
|
161
93
|
if (!userOrRoleId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'parameter', 'User nor a Role');
|
|
@@ -3,38 +3,21 @@
|
|
|
3
3
|
const CachedManager = require('./CachedManager');
|
|
4
4
|
const { Presence } = require('../structures/Presence');
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
* Manages API methods for Presences and holds their cache.
|
|
8
|
-
* @extends {CachedManager}
|
|
9
|
-
*/
|
|
6
|
+
|
|
10
7
|
class PresenceManager extends CachedManager {
|
|
11
8
|
constructor(client, iterable) {
|
|
12
9
|
super(client, Presence, iterable);
|
|
13
10
|
}
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
* The cache of Presences
|
|
17
|
-
* @type {Collection<Snowflake, Presence>}
|
|
18
|
-
* @name PresenceManager#cache
|
|
19
|
-
*/
|
|
12
|
+
|
|
20
13
|
|
|
21
14
|
_add(data, cache) {
|
|
22
15
|
return super._add(data, cache, { id: data.user.id });
|
|
23
16
|
}
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* * A UserResolvable
|
|
29
|
-
* * A Snowflake
|
|
30
|
-
* @typedef {Presence|UserResolvable|Snowflake} PresenceResolvable
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Resolves a {@link PresenceResolvable} to a {@link Presence} object.
|
|
35
|
-
* @param {PresenceResolvable} presence The presence resolvable to resolve
|
|
36
|
-
* @returns {?Presence}
|
|
37
|
-
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
38
21
|
resolve(presence) {
|
|
39
22
|
const presenceResolvable = super.resolve(presence);
|
|
40
23
|
if (presenceResolvable) return presenceResolvable;
|
|
@@ -42,11 +25,7 @@ class PresenceManager extends CachedManager {
|
|
|
42
25
|
return super.resolve(UserResolvable);
|
|
43
26
|
}
|
|
44
27
|
|
|
45
|
-
|
|
46
|
-
* Resolves a {@link PresenceResolvable} to a {@link Presence} id.
|
|
47
|
-
* @param {PresenceResolvable} presence The presence resolvable to resolve
|
|
48
|
-
* @returns {?Snowflake}
|
|
49
|
-
*/
|
|
28
|
+
|
|
50
29
|
resolveId(presence) {
|
|
51
30
|
const presenceResolvable = super.resolveId(presence);
|
|
52
31
|
if (presenceResolvable) return presenceResolvable;
|
|
@@ -4,18 +4,12 @@ const { Routes } = require('discord-api-types/v10');
|
|
|
4
4
|
const CachedManager = require('./CachedManager');
|
|
5
5
|
const MessageReaction = require('../structures/MessageReaction');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
* Manages API methods for reactions and holds their cache.
|
|
9
|
-
* @extends {CachedManager}
|
|
10
|
-
*/
|
|
7
|
+
|
|
11
8
|
class ReactionManager extends CachedManager {
|
|
12
9
|
constructor(message, iterable) {
|
|
13
10
|
super(message.client, MessageReaction, iterable);
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
* The message that this manager belongs to
|
|
17
|
-
* @type {Message}
|
|
18
|
-
*/
|
|
12
|
+
|
|
19
13
|
this.message = message;
|
|
20
14
|
}
|
|
21
15
|
|
|
@@ -23,42 +17,15 @@ class ReactionManager extends CachedManager {
|
|
|
23
17
|
return super._add(data, cache, { id: data.emoji.id ?? data.emoji.name, extras: [this.message] });
|
|
24
18
|
}
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
* The reaction cache of this manager
|
|
28
|
-
* @type {Collection<string|Snowflake, MessageReaction>}
|
|
29
|
-
* @name ReactionManager#cache
|
|
30
|
-
*/
|
|
20
|
+
|
|
31
21
|
|
|
32
|
-
|
|
33
|
-
* Data that can be resolved to a MessageReaction object. This can be:
|
|
34
|
-
* * A MessageReaction
|
|
35
|
-
* * A Snowflake
|
|
36
|
-
* * The Unicode representation of an emoji
|
|
37
|
-
* @typedef {MessageReaction|Snowflake} MessageReactionResolvable
|
|
38
|
-
*/
|
|
22
|
+
|
|
39
23
|
|
|
40
|
-
|
|
41
|
-
* Resolves a {@link MessageReactionResolvable} to a {@link MessageReaction} object.
|
|
42
|
-
* @method resolve
|
|
43
|
-
* @memberof ReactionManager
|
|
44
|
-
* @instance
|
|
45
|
-
* @param {MessageReactionResolvable} reaction The MessageReaction to resolve
|
|
46
|
-
* @returns {?MessageReaction}
|
|
47
|
-
*/
|
|
24
|
+
|
|
48
25
|
|
|
49
|
-
|
|
50
|
-
* Resolves a {@link MessageReactionResolvable} to a {@link MessageReaction} id.
|
|
51
|
-
* @method resolveId
|
|
52
|
-
* @memberof ReactionManager
|
|
53
|
-
* @instance
|
|
54
|
-
* @param {MessageReactionResolvable} reaction The MessageReaction to resolve
|
|
55
|
-
* @returns {?Snowflake}
|
|
56
|
-
*/
|
|
26
|
+
|
|
57
27
|
|
|
58
|
-
|
|
59
|
-
* Removes all reactions from a message.
|
|
60
|
-
* @returns {Promise<Message>}
|
|
61
|
-
*/
|
|
28
|
+
|
|
62
29
|
async removeAll() {
|
|
63
30
|
await this.client.rest.delete(Routes.channelMessageAllReactions(this.message.channelId, this.message.id));
|
|
64
31
|
return this.message;
|
|
@@ -7,39 +7,20 @@ const CachedManager = require('./CachedManager');
|
|
|
7
7
|
const { DiscordjsError, ErrorCodes } = require('../errors');
|
|
8
8
|
const User = require('../structures/User');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
* Manages API methods for users who reacted to a reaction and stores their cache.
|
|
12
|
-
* @extends {CachedManager}
|
|
13
|
-
*/
|
|
10
|
+
|
|
14
11
|
class ReactionUserManager extends CachedManager {
|
|
15
12
|
constructor(reaction, iterable) {
|
|
16
13
|
super(reaction.client, User, iterable);
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
* The reaction that this manager belongs to
|
|
20
|
-
* @type {MessageReaction}
|
|
21
|
-
*/
|
|
15
|
+
|
|
22
16
|
this.reaction = reaction;
|
|
23
17
|
}
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
* The cache of this manager
|
|
27
|
-
* @type {Collection<Snowflake, User>}
|
|
28
|
-
* @name ReactionUserManager#cache
|
|
29
|
-
*/
|
|
19
|
+
|
|
30
20
|
|
|
31
|
-
|
|
32
|
-
* Options used to fetch users who gave a reaction.
|
|
33
|
-
* @typedef {Object} FetchReactionUsersOptions
|
|
34
|
-
* @property {number} [limit=100] The maximum amount of users to fetch, defaults to `100`
|
|
35
|
-
* @property {Snowflake} [after] Limit fetching users to those with an id greater than the supplied id
|
|
36
|
-
*/
|
|
21
|
+
|
|
37
22
|
|
|
38
|
-
|
|
39
|
-
* Fetches all the users that gave this reaction. Resolves with a collection of users, mapped by their ids.
|
|
40
|
-
* @param {FetchReactionUsersOptions} [options] Options for fetching the users
|
|
41
|
-
* @returns {Promise<Collection<Snowflake, User>>}
|
|
42
|
-
*/
|
|
23
|
+
|
|
43
24
|
async fetch({ limit = 100, after } = {}) {
|
|
44
25
|
const message = this.reaction.message;
|
|
45
26
|
const query = makeURLSearchParams({ limit, after });
|
|
@@ -56,11 +37,7 @@ class ReactionUserManager extends CachedManager {
|
|
|
56
37
|
return users;
|
|
57
38
|
}
|
|
58
39
|
|
|
59
|
-
|
|
60
|
-
* Removes a user from this reaction.
|
|
61
|
-
* @param {UserResolvable} [user=this.client.user] The user to remove the reaction of
|
|
62
|
-
* @returns {Promise<MessageReaction>}
|
|
63
|
-
*/
|
|
40
|
+
|
|
64
41
|
async remove(user = this.client.user) {
|
|
65
42
|
const userId = this.client.users.resolveId(user);
|
|
66
43
|
if (!userId) throw new DiscordjsError(ErrorCodes.ReactionResolveUser);
|
|
@@ -12,10 +12,7 @@ const { setPosition, resolveColor } = require('../util/Util');
|
|
|
12
12
|
|
|
13
13
|
let cacheWarningEmitted = false;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
* Manages API methods for roles and stores their cache.
|
|
17
|
-
* @extends {CachedManager}
|
|
18
|
-
*/
|
|
15
|
+
|
|
19
16
|
class RoleManager extends CachedManager {
|
|
20
17
|
constructor(guild, iterable) {
|
|
21
18
|
super(guild.client, Role, iterable);
|
|
@@ -27,113 +24,39 @@ class RoleManager extends CachedManager {
|
|
|
27
24
|
);
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
* The guild belonging to this manager
|
|
32
|
-
* @type {Guild}
|
|
33
|
-
*/
|
|
27
|
+
|
|
34
28
|
this.guild = guild;
|
|
35
29
|
}
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
* The role cache of this manager
|
|
39
|
-
* @type {Collection<Snowflake, Role>}
|
|
40
|
-
* @name RoleManager#cache
|
|
41
|
-
*/
|
|
31
|
+
|
|
42
32
|
|
|
43
33
|
_add(data, cache) {
|
|
44
34
|
return super._add(data, cache, { extras: [this.guild] });
|
|
45
35
|
}
|
|
46
36
|
|
|
47
|
-
|
|
48
|
-
* Obtains a role from Discord, or the role cache if they're already available.
|
|
49
|
-
* @param {Snowflake} [id] The role's id
|
|
50
|
-
* @param {BaseFetchOptions} [options] Additional options for this fetch
|
|
51
|
-
* @returns {Promise<?Role|Collection<Snowflake, Role>>}
|
|
52
|
-
* @example
|
|
53
|
-
* // Fetch all roles from the guild
|
|
54
|
-
* message.guild.roles.fetch()
|
|
55
|
-
* .then(roles => console.log(`There are ${roles.size} roles.`))
|
|
56
|
-
* .catch(console.error);
|
|
57
|
-
* @example
|
|
58
|
-
* // Fetch a single role
|
|
59
|
-
* message.guild.roles.fetch('222078108977594368')
|
|
60
|
-
* .then(role => console.log(`The role color is: ${role.color}`))
|
|
61
|
-
* .catch(console.error);
|
|
62
|
-
*/
|
|
37
|
+
|
|
63
38
|
async fetch(id, { cache = true, force = false } = {}) {
|
|
64
39
|
if (id && !force) {
|
|
65
40
|
const existing = this.cache.get(id);
|
|
66
41
|
if (existing) return existing;
|
|
67
42
|
}
|
|
68
43
|
|
|
69
|
-
|
|
44
|
+
|
|
70
45
|
const data = await this.client.rest.get(Routes.guildRoles(this.guild.id));
|
|
71
46
|
const roles = new Collection();
|
|
72
47
|
for (const role of data) roles.set(role.id, this._add(role, cache));
|
|
73
48
|
return id ? roles.get(id) ?? null : roles;
|
|
74
49
|
}
|
|
75
50
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* @method resolve
|
|
86
|
-
* @memberof RoleManager
|
|
87
|
-
* @instance
|
|
88
|
-
* @param {RoleResolvable} role The role resolvable to resolve
|
|
89
|
-
* @returns {?Role}
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Resolves a {@link RoleResolvable} to a {@link Role} id.
|
|
94
|
-
* @method resolveId
|
|
95
|
-
* @memberof RoleManager
|
|
96
|
-
* @instance
|
|
97
|
-
* @param {RoleResolvable} role The role resolvable to resolve
|
|
98
|
-
* @returns {?Snowflake}
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Options used to create a new role.
|
|
103
|
-
* @typedef {Object} RoleCreateOptions
|
|
104
|
-
* @property {string} [name] The name of the new role
|
|
105
|
-
* @property {ColorResolvable} [color] The data to create the role with
|
|
106
|
-
* @property {boolean} [hoist] Whether or not the new role should be hoisted
|
|
107
|
-
* @property {PermissionResolvable} [permissions] The permissions for the new role
|
|
108
|
-
* @property {number} [position] The position of the new role
|
|
109
|
-
* @property {boolean} [mentionable] Whether or not the new role should be mentionable
|
|
110
|
-
* @property {?(BufferResolvable|Base64Resolvable|EmojiResolvable)} [icon] The icon for the role
|
|
111
|
-
* <warn>The `EmojiResolvable` should belong to the same guild as the role.
|
|
112
|
-
* If not, pass the emoji's URL directly</warn>
|
|
113
|
-
* @property {?string} [unicodeEmoji] The unicode emoji for the role
|
|
114
|
-
* @property {string} [reason] The reason for creating this role
|
|
115
|
-
*/
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Creates a new role in the guild with given information.
|
|
119
|
-
* <warn>The position will silently reset to 1 if an invalid one is provided, or none.</warn>
|
|
120
|
-
* @param {RoleCreateOptions} [options] Options for creating the new role
|
|
121
|
-
* @returns {Promise<Role>}
|
|
122
|
-
* @example
|
|
123
|
-
* // Create a new role
|
|
124
|
-
* guild.roles.create()
|
|
125
|
-
* .then(console.log)
|
|
126
|
-
* .catch(console.error);
|
|
127
|
-
* @example
|
|
128
|
-
* // Create a new role with data and a reason
|
|
129
|
-
* guild.roles.create({
|
|
130
|
-
* name: 'Super Cool Blue People',
|
|
131
|
-
* color: Colors.Blue,
|
|
132
|
-
* reason: 'we needed a role for Super Cool People',
|
|
133
|
-
* })
|
|
134
|
-
* .then(console.log)
|
|
135
|
-
* .catch(console.error);
|
|
136
|
-
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
137
60
|
async create(options = {}) {
|
|
138
61
|
let { name, color, hoist, permissions, position, mentionable, reason, icon, unicodeEmoji } = options;
|
|
139
62
|
color &&= resolveColor(color);
|
|
@@ -164,23 +87,9 @@ class RoleManager extends CachedManager {
|
|
|
164
87
|
return role;
|
|
165
88
|
}
|
|
166
89
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
* @property {string} [reason] The reason for editing this role
|
|
171
|
-
*/
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Edits a role of the guild.
|
|
175
|
-
* @param {RoleResolvable} role The role to edit
|
|
176
|
-
* @param {RoleEditOptions} options The options to provide
|
|
177
|
-
* @returns {Promise<Role>}
|
|
178
|
-
* @example
|
|
179
|
-
* // Edit a role
|
|
180
|
-
* guild.roles.edit('222079219327434752', { name: 'buddies' })
|
|
181
|
-
* .then(updated => console.log(`Edited role name to ${updated.name}`))
|
|
182
|
-
* .catch(console.error);
|
|
183
|
-
*/
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
184
93
|
async edit(role, options) {
|
|
185
94
|
role = this.resolve(role);
|
|
186
95
|
if (!role) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'role', 'RoleResolvable');
|
|
@@ -213,35 +122,14 @@ class RoleManager extends CachedManager {
|
|
|
213
122
|
return clone;
|
|
214
123
|
}
|
|
215
124
|
|
|
216
|
-
|
|
217
|
-
* Deletes a role.
|
|
218
|
-
* @param {RoleResolvable} role The role to delete
|
|
219
|
-
* @param {string} [reason] Reason for deleting the role
|
|
220
|
-
* @returns {Promise<void>}
|
|
221
|
-
* @example
|
|
222
|
-
* // Delete a role
|
|
223
|
-
* guild.roles.delete('222079219327434752', 'The role needed to go')
|
|
224
|
-
* .then(() => console.log('Deleted the role'))
|
|
225
|
-
* .catch(console.error);
|
|
226
|
-
*/
|
|
125
|
+
|
|
227
126
|
async delete(role, reason) {
|
|
228
127
|
const id = this.resolveId(role);
|
|
229
128
|
await this.client.rest.delete(Routes.guildRole(this.guild.id, id), { reason });
|
|
230
129
|
this.client.actions.GuildRoleDelete.handle({ guild_id: this.guild.id, role_id: id });
|
|
231
130
|
}
|
|
232
131
|
|
|
233
|
-
|
|
234
|
-
* Sets the new position of the role.
|
|
235
|
-
* @param {RoleResolvable} role The role to change the position of
|
|
236
|
-
* @param {number} position The new position for the role
|
|
237
|
-
* @param {SetRolePositionOptions} [options] Options for setting the position
|
|
238
|
-
* @returns {Promise<Role>}
|
|
239
|
-
* @example
|
|
240
|
-
* // Set the position of the role
|
|
241
|
-
* guild.roles.setPosition('222197033908436994', 1)
|
|
242
|
-
* .then(updated => console.log(`Role position: ${updated.position}`))
|
|
243
|
-
* .catch(console.error);
|
|
244
|
-
*/
|
|
132
|
+
|
|
245
133
|
async setPosition(role, position, { relative, reason } = {}) {
|
|
246
134
|
role = this.resolve(role);
|
|
247
135
|
if (!role) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'role', 'RoleResolvable');
|
|
@@ -262,30 +150,17 @@ class RoleManager extends CachedManager {
|
|
|
262
150
|
return role;
|
|
263
151
|
}
|
|
264
152
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
* @property {RoleResolvable} role The role's id
|
|
269
|
-
* @property {number} position The position to update
|
|
270
|
-
*/
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Batch-updates the guild's role positions
|
|
274
|
-
* @param {GuildRolePosition[]} rolePositions Role positions to update
|
|
275
|
-
* @returns {Promise<Guild>}
|
|
276
|
-
* @example
|
|
277
|
-
* guild.roles.setPositions([{ role: roleId, position: updatedRoleIndex }])
|
|
278
|
-
* .then(guild => console.log(`Role positions updated for ${guild}`))
|
|
279
|
-
* .catch(console.error);
|
|
280
|
-
*/
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
281
156
|
async setPositions(rolePositions) {
|
|
282
|
-
|
|
157
|
+
|
|
283
158
|
rolePositions = rolePositions.map(o => ({
|
|
284
159
|
id: this.resolveId(o.role),
|
|
285
160
|
position: o.position,
|
|
286
161
|
}));
|
|
287
162
|
|
|
288
|
-
|
|
163
|
+
|
|
289
164
|
await this.client.rest.patch(Routes.guildRoles(this.guild.id), { body: rolePositions });
|
|
290
165
|
return this.client.actions.GuildRolesPositionUpdate.handle({
|
|
291
166
|
guild_id: this.guild.id,
|
|
@@ -293,13 +168,7 @@ class RoleManager extends CachedManager {
|
|
|
293
168
|
}).guild;
|
|
294
169
|
}
|
|
295
170
|
|
|
296
|
-
|
|
297
|
-
* Compares the positions of two roles.
|
|
298
|
-
* @param {RoleResolvable} role1 First role to compare
|
|
299
|
-
* @param {RoleResolvable} role2 Second role to compare
|
|
300
|
-
* @returns {number} Negative number if the first role's position is lower (second role's is higher),
|
|
301
|
-
* positive number if the first's is higher (second's is lower), 0 if equal
|
|
302
|
-
*/
|
|
171
|
+
|
|
303
172
|
comparePositions(role1, role2) {
|
|
304
173
|
const resolvedRole1 = this.resolve(role1);
|
|
305
174
|
const resolvedRole2 = this.resolve(role2);
|
|
@@ -317,41 +186,24 @@ class RoleManager extends CachedManager {
|
|
|
317
186
|
return role1Position - role2Position;
|
|
318
187
|
}
|
|
319
188
|
|
|
320
|
-
|
|
321
|
-
* Gets the managed role a user created when joining the guild, if any
|
|
322
|
-
* <info>Only ever available for bots</info>
|
|
323
|
-
* @param {UserResolvable} user The user to access the bot role for
|
|
324
|
-
* @returns {?Role}
|
|
325
|
-
*/
|
|
189
|
+
|
|
326
190
|
botRoleFor(user) {
|
|
327
191
|
const userId = this.client.users.resolveId(user);
|
|
328
192
|
if (!userId) return null;
|
|
329
193
|
return this.cache.find(role => role.tags?.botId === userId) ?? null;
|
|
330
194
|
}
|
|
331
195
|
|
|
332
|
-
|
|
333
|
-
* The `@everyone` role of the guild
|
|
334
|
-
* @type {Role}
|
|
335
|
-
* @readonly
|
|
336
|
-
*/
|
|
196
|
+
|
|
337
197
|
get everyone() {
|
|
338
198
|
return this.cache.get(this.guild.id);
|
|
339
199
|
}
|
|
340
200
|
|
|
341
|
-
|
|
342
|
-
* The premium subscriber role of the guild, if any
|
|
343
|
-
* @type {?Role}
|
|
344
|
-
* @readonly
|
|
345
|
-
*/
|
|
201
|
+
|
|
346
202
|
get premiumSubscriberRole() {
|
|
347
203
|
return this.cache.find(role => role.tags?.premiumSubscriberRole) ?? null;
|
|
348
204
|
}
|
|
349
205
|
|
|
350
|
-
|
|
351
|
-
* The role with the highest position in the cache
|
|
352
|
-
* @type {Role}
|
|
353
|
-
* @readonly
|
|
354
|
-
*/
|
|
206
|
+
|
|
355
207
|
get highest() {
|
|
356
208
|
return this.cache.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev), this.cache.first());
|
|
357
209
|
}
|