@velliajs/discord 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +133 -0
- package/package.json +82 -0
- package/src/client/BaseClient.js +83 -0
- package/src/client/Client.js +591 -0
- package/src/client/WebhookClient.js +103 -0
- package/src/client/actions/Action.js +119 -0
- package/src/client/actions/ActionsManager.js +79 -0
- package/src/client/actions/ApplicationCommandPermissionsUpdate.js +34 -0
- package/src/client/actions/AutoModerationActionExecution.js +26 -0
- package/src/client/actions/AutoModerationRuleCreate.js +27 -0
- package/src/client/actions/AutoModerationRuleDelete.js +31 -0
- package/src/client/actions/AutoModerationRuleUpdate.js +29 -0
- package/src/client/actions/ChannelCreate.js +23 -0
- package/src/client/actions/ChannelDelete.js +23 -0
- package/src/client/actions/ChannelUpdate.js +33 -0
- package/src/client/actions/GuildAuditLogEntryCreate.js +29 -0
- package/src/client/actions/GuildBanAdd.js +20 -0
- package/src/client/actions/GuildBanRemove.js +25 -0
- package/src/client/actions/GuildChannelsPositionUpdate.js +21 -0
- package/src/client/actions/GuildDelete.js +44 -0
- package/src/client/actions/GuildEmojiCreate.js +20 -0
- package/src/client/actions/GuildEmojiDelete.js +19 -0
- package/src/client/actions/GuildEmojiUpdate.js +20 -0
- package/src/client/actions/GuildEmojisUpdate.js +34 -0
- package/src/client/actions/GuildIntegrationsUpdate.js +19 -0
- package/src/client/actions/GuildMemberRemove.js +31 -0
- package/src/client/actions/GuildMemberUpdate.js +44 -0
- package/src/client/actions/GuildRoleCreate.js +25 -0
- package/src/client/actions/GuildRoleDelete.js +29 -0
- package/src/client/actions/GuildRoleUpdate.js +39 -0
- package/src/client/actions/GuildRolesPositionUpdate.js +21 -0
- package/src/client/actions/GuildScheduledEventCreate.js +27 -0
- package/src/client/actions/GuildScheduledEventDelete.js +31 -0
- package/src/client/actions/GuildScheduledEventUpdate.js +30 -0
- package/src/client/actions/GuildScheduledEventUserAdd.js +32 -0
- package/src/client/actions/GuildScheduledEventUserRemove.js +32 -0
- package/src/client/actions/GuildStickerCreate.js +20 -0
- package/src/client/actions/GuildStickerDelete.js +19 -0
- package/src/client/actions/GuildStickerUpdate.js +20 -0
- package/src/client/actions/GuildStickersUpdate.js +34 -0
- package/src/client/actions/GuildUpdate.js +33 -0
- package/src/client/actions/InteractionCreate.js +101 -0
- package/src/client/actions/InviteCreate.js +28 -0
- package/src/client/actions/InviteDelete.js +30 -0
- package/src/client/actions/MessageCreate.js +37 -0
- package/src/client/actions/MessageDelete.js +32 -0
- package/src/client/actions/MessageDeleteBulk.js +47 -0
- package/src/client/actions/MessageReactionAdd.js +55 -0
- package/src/client/actions/MessageReactionRemove.js +45 -0
- package/src/client/actions/MessageReactionRemoveAll.js +33 -0
- package/src/client/actions/MessageReactionRemoveEmoji.js +28 -0
- package/src/client/actions/MessageUpdate.js +26 -0
- package/src/client/actions/PresenceUpdate.js +42 -0
- package/src/client/actions/StageInstanceCreate.js +28 -0
- package/src/client/actions/StageInstanceDelete.js +31 -0
- package/src/client/actions/StageInstanceUpdate.js +30 -0
- package/src/client/actions/ThreadCreate.js +24 -0
- package/src/client/actions/ThreadDelete.js +26 -0
- package/src/client/actions/ThreadListSync.js +60 -0
- package/src/client/actions/ThreadMemberUpdate.js +30 -0
- package/src/client/actions/ThreadMembersUpdate.js +47 -0
- package/src/client/actions/TypingStart.js +29 -0
- package/src/client/actions/UserUpdate.js +36 -0
- package/src/client/actions/VoiceStateUpdate.js +43 -0
- package/src/client/actions/WebhooksUpdate.js +20 -0
- package/src/client/voice/ClientVoiceManager.js +44 -0
- package/src/client/websocket/WebSocketManager.js +393 -0
- package/src/client/websocket/WebSocketShard.js +231 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +22 -0
- package/src/client/websocket/handlers/CHANNEL_UPDATE.js +16 -0
- package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_BAN_ADD.js +5 -0
- package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_CREATE.js +26 -0
- package/src/client/websocket/handlers/GUILD_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +39 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +20 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
- package/src/client/websocket/handlers/INTERACTION_CREATE.js +5 -0
- package/src/client/websocket/handlers/INVITE_CREATE.js +5 -0
- package/src/client/websocket/handlers/INVITE_DELETE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_UPDATE.js +16 -0
- package/src/client/websocket/handlers/PRESENCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/READY.js +27 -0
- package/src/client/websocket/handlers/RESUMED.js +14 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_DELETE.js +5 -0
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -0
- package/src/client/websocket/handlers/TYPING_START.js +5 -0
- package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +6 -0
- package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/index.js +64 -0
- package/src/errors/DJSError.js +48 -0
- package/src/errors/ErrorCodes.js +319 -0
- package/src/errors/Messages.js +170 -0
- package/src/errors/index.js +5 -0
- package/src/index.js +213 -0
- package/src/managers/ApplicationCommandManager.js +263 -0
- package/src/managers/ApplicationCommandPermissionsManager.js +434 -0
- package/src/managers/AutoModerationRuleManager.js +288 -0
- package/src/managers/BaseGuildEmojiManager.js +80 -0
- package/src/managers/BaseManager.js +19 -0
- package/src/managers/CachedManager.js +57 -0
- package/src/managers/CategoryChannelChildManager.js +77 -0
- package/src/managers/ChannelManager.js +128 -0
- package/src/managers/DataManager.js +61 -0
- package/src/managers/GuildApplicationCommandManager.js +28 -0
- package/src/managers/GuildBanManager.js +204 -0
- package/src/managers/GuildChannelManager.js +494 -0
- package/src/managers/GuildEmojiManager.js +174 -0
- package/src/managers/GuildEmojiRoleManager.js +118 -0
- package/src/managers/GuildForumThreadManager.js +83 -0
- package/src/managers/GuildInviteManager.js +213 -0
- package/src/managers/GuildManager.js +283 -0
- package/src/managers/GuildMemberManager.js +540 -0
- package/src/managers/GuildMemberRoleManager.js +204 -0
- package/src/managers/GuildScheduledEventManager.js +297 -0
- package/src/managers/GuildStickerManager.js +182 -0
- package/src/managers/GuildTextThreadManager.js +91 -0
- package/src/managers/MessageManager.js +259 -0
- package/src/managers/PermissionOverwriteManager.js +168 -0
- package/src/managers/PresenceManager.js +58 -0
- package/src/managers/ReactionManager.js +68 -0
- package/src/managers/ReactionUserManager.js +77 -0
- package/src/managers/RoleManager.js +360 -0
- package/src/managers/StageInstanceManager.js +154 -0
- package/src/managers/ThreadManager.js +204 -0
- package/src/managers/ThreadMemberManager.js +182 -0
- package/src/managers/UserManager.js +139 -0
- package/src/managers/VoiceStateManager.js +37 -0
- package/src/sharding/Shard.js +457 -0
- package/src/sharding/ShardClientUtil.js +285 -0
- package/src/sharding/ShardingManager.js +326 -0
- package/src/structures/ActionRow.js +46 -0
- package/src/structures/ActionRowBuilder.js +35 -0
- package/src/structures/AnonymousGuild.js +97 -0
- package/src/structures/ApplicationCommand.js +606 -0
- package/src/structures/ApplicationRoleConnectionMetadata.js +46 -0
- package/src/structures/Attachment.js +140 -0
- package/src/structures/AttachmentBuilder.js +116 -0
- package/src/structures/AutoModerationActionExecution.js +116 -0
- package/src/structures/AutoModerationRule.js +284 -0
- package/src/structures/AutocompleteInteraction.js +97 -0
- package/src/structures/Base.js +43 -0
- package/src/structures/BaseChannel.js +160 -0
- package/src/structures/BaseGuild.js +119 -0
- package/src/structures/BaseGuildEmoji.js +56 -0
- package/src/structures/BaseGuildTextChannel.js +186 -0
- package/src/structures/BaseGuildVoiceChannel.js +234 -0
- package/src/structures/BaseInteraction.js +344 -0
- package/src/structures/BaseSelectMenuComponent.js +56 -0
- package/src/structures/ButtonBuilder.js +44 -0
- package/src/structures/ButtonComponent.js +65 -0
- package/src/structures/ButtonInteraction.js +11 -0
- package/src/structures/CategoryChannel.js +45 -0
- package/src/structures/ChannelSelectMenuBuilder.js +31 -0
- package/src/structures/ChannelSelectMenuComponent.js +20 -0
- package/src/structures/ChannelSelectMenuInteraction.js +33 -0
- package/src/structures/ChatInputCommandInteraction.js +41 -0
- package/src/structures/ClientApplication.js +193 -0
- package/src/structures/ClientPresence.js +82 -0
- package/src/structures/ClientUser.js +185 -0
- package/src/structures/CommandInteraction.js +224 -0
- package/src/structures/CommandInteractionOptionResolver.js +308 -0
- package/src/structures/Component.js +47 -0
- package/src/structures/ContextMenuCommandInteraction.js +64 -0
- package/src/structures/DMChannel.js +129 -0
- package/src/structures/DirectoryChannel.js +36 -0
- package/src/structures/Embed.js +220 -0
- package/src/structures/EmbedBuilder.js +41 -0
- package/src/structures/Emoji.js +108 -0
- package/src/structures/ForumChannel.js +264 -0
- package/src/structures/Guild.js +1361 -0
- package/src/structures/GuildAuditLogs.js +91 -0
- package/src/structures/GuildAuditLogsEntry.js +527 -0
- package/src/structures/GuildBan.js +59 -0
- package/src/structures/GuildChannel.js +457 -0
- package/src/structures/GuildEmoji.js +148 -0
- package/src/structures/GuildMember.js +518 -0
- package/src/structures/GuildPreview.js +193 -0
- package/src/structures/GuildPreviewEmoji.js +27 -0
- package/src/structures/GuildScheduledEvent.js +439 -0
- package/src/structures/GuildTemplate.js +241 -0
- package/src/structures/Integration.js +220 -0
- package/src/structures/IntegrationApplication.js +85 -0
- package/src/structures/InteractionCollector.js +263 -0
- package/src/structures/InteractionResponse.js +102 -0
- package/src/structures/InteractionWebhook.js +59 -0
- package/src/structures/Invite.js +322 -0
- package/src/structures/InviteGuild.js +22 -0
- package/src/structures/InviteStageInstance.js +87 -0
- package/src/structures/MentionableSelectMenuBuilder.js +32 -0
- package/src/structures/MentionableSelectMenuComponent.js +11 -0
- package/src/structures/MentionableSelectMenuInteraction.js +71 -0
- package/src/structures/Message.js +997 -0
- package/src/structures/MessageCollector.js +146 -0
- package/src/structures/MessageComponentInteraction.js +107 -0
- package/src/structures/MessageContextMenuCommandInteraction.js +20 -0
- package/src/structures/MessageMentions.js +297 -0
- package/src/structures/MessagePayload.js +299 -0
- package/src/structures/MessageReaction.js +142 -0
- package/src/structures/ModalBuilder.js +34 -0
- package/src/structures/ModalSubmitFields.js +55 -0
- package/src/structures/ModalSubmitInteraction.js +121 -0
- package/src/structures/NewsChannel.js +32 -0
- package/src/structures/OAuth2Guild.js +28 -0
- package/src/structures/PartialGroupDMChannel.js +60 -0
- package/src/structures/PermissionOverwrites.js +196 -0
- package/src/structures/Presence.js +372 -0
- package/src/structures/ReactionCollector.js +229 -0
- package/src/structures/ReactionEmoji.js +31 -0
- package/src/structures/Role.js +458 -0
- package/src/structures/RoleSelectMenuBuilder.js +31 -0
- package/src/structures/RoleSelectMenuComponent.js +11 -0
- package/src/structures/RoleSelectMenuInteraction.js +33 -0
- package/src/structures/SelectMenuBuilder.js +26 -0
- package/src/structures/SelectMenuComponent.js +26 -0
- package/src/structures/SelectMenuInteraction.js +26 -0
- package/src/structures/SelectMenuOptionBuilder.js +26 -0
- package/src/structures/StageChannel.js +112 -0
- package/src/structures/StageInstance.js +167 -0
- package/src/structures/Sticker.js +272 -0
- package/src/structures/StickerPack.js +95 -0
- package/src/structures/StringSelectMenuBuilder.js +79 -0
- package/src/structures/StringSelectMenuComponent.js +20 -0
- package/src/structures/StringSelectMenuInteraction.js +21 -0
- package/src/structures/StringSelectMenuOptionBuilder.js +49 -0
- package/src/structures/Team.js +117 -0
- package/src/structures/TeamMember.js +70 -0
- package/src/structures/TextChannel.js +33 -0
- package/src/structures/TextInputBuilder.js +31 -0
- package/src/structures/TextInputComponent.js +29 -0
- package/src/structures/ThreadChannel.js +606 -0
- package/src/structures/ThreadMember.js +113 -0
- package/src/structures/Typing.js +74 -0
- package/src/structures/User.js +331 -0
- package/src/structures/UserContextMenuCommandInteraction.js +29 -0
- package/src/structures/UserSelectMenuBuilder.js +31 -0
- package/src/structures/UserSelectMenuComponent.js +11 -0
- package/src/structures/UserSelectMenuInteraction.js +51 -0
- package/src/structures/VoiceChannel.js +96 -0
- package/src/structures/VoiceRegion.js +46 -0
- package/src/structures/VoiceState.js +303 -0
- package/src/structures/Webhook.js +481 -0
- package/src/structures/WelcomeChannel.js +60 -0
- package/src/structures/WelcomeScreen.js +49 -0
- package/src/structures/Widget.js +88 -0
- package/src/structures/WidgetMember.js +99 -0
- package/src/structures/interfaces/Application.js +108 -0
- package/src/structures/interfaces/Collector.js +335 -0
- package/src/structures/interfaces/InteractionResponses.js +320 -0
- package/src/structures/interfaces/TextBasedChannel.js +413 -0
- package/src/util/APITypes.js +456 -0
- package/src/util/ActivityFlagsBitField.js +26 -0
- package/src/util/ApplicationFlagsBitField.js +26 -0
- package/src/util/BitField.js +176 -0
- package/src/util/ChannelFlagsBitField.js +41 -0
- package/src/util/Channels.js +150 -0
- package/src/util/Colors.js +73 -0
- package/src/util/Components.js +152 -0
- package/src/util/Constants.js +230 -0
- package/src/util/DataResolver.js +140 -0
- package/src/util/Enums.js +13 -0
- package/src/util/Events.js +160 -0
- package/src/util/Formatters.js +413 -0
- package/src/util/GuildMemberFlagsBitField.js +41 -0
- package/src/util/IntentsBitField.js +34 -0
- package/src/util/LimitedCollection.js +68 -0
- package/src/util/MessageFlagsBitField.js +32 -0
- package/src/util/Options.js +216 -0
- package/src/util/Partials.js +44 -0
- package/src/util/PermissionsBitField.js +104 -0
- package/src/util/ShardEvents.js +27 -0
- package/src/util/Status.js +33 -0
- package/src/util/Sweepers.js +467 -0
- package/src/util/SystemChannelFlagsBitField.js +43 -0
- package/src/util/ThreadMemberFlagsBitField.js +31 -0
- package/src/util/Transformers.js +36 -0
- package/src/util/UserFlagsBitField.js +32 -0
- package/src/util/Util.js +394 -0
- package/src/util/WebSocketShardEvents.js +25 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Collection } = require('@discordjs/collection');
|
|
4
|
+
const DataManager = require('./DataManager');
|
|
5
|
+
const { DiscordjsTypeError, ErrorCodes } = require('../errors');
|
|
6
|
+
const { Role } = require('../structures/Role');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Manages API methods for roles belonging to emojis and stores their cache.
|
|
10
|
+
* @extends {DataManager}
|
|
11
|
+
*/
|
|
12
|
+
class GuildEmojiRoleManager extends DataManager {
|
|
13
|
+
constructor(emoji) {
|
|
14
|
+
super(emoji.client, Role);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The emoji belonging to this manager
|
|
18
|
+
* @type {GuildEmoji}
|
|
19
|
+
*/
|
|
20
|
+
this.emoji = emoji;
|
|
21
|
+
/**
|
|
22
|
+
* The guild belonging to this manager
|
|
23
|
+
* @type {Guild}
|
|
24
|
+
*/
|
|
25
|
+
this.guild = emoji.guild;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The cache of roles belonging to this emoji
|
|
30
|
+
* @type {Collection<Snowflake, Role>}
|
|
31
|
+
* @readonly
|
|
32
|
+
*/
|
|
33
|
+
get cache() {
|
|
34
|
+
return this.guild.roles.cache.filter(role => this.emoji._roles.includes(role.id));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Adds a role (or multiple roles) to the list of roles that can use this emoji.
|
|
39
|
+
* @param {RoleResolvable|RoleResolvable[]|Collection<Snowflake, Role>} roleOrRoles The role or roles to add
|
|
40
|
+
* @returns {Promise<GuildEmoji>}
|
|
41
|
+
*/
|
|
42
|
+
add(roleOrRoles) {
|
|
43
|
+
if (!Array.isArray(roleOrRoles) && !(roleOrRoles instanceof Collection)) roleOrRoles = [roleOrRoles];
|
|
44
|
+
|
|
45
|
+
const resolvedRoles = [];
|
|
46
|
+
for (const role of roleOrRoles.values()) {
|
|
47
|
+
const resolvedRole = this.guild.roles.resolveId(role);
|
|
48
|
+
if (!resolvedRole) {
|
|
49
|
+
return Promise.reject(new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array or Collection', 'roles', role));
|
|
50
|
+
}
|
|
51
|
+
resolvedRoles.push(resolvedRole);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const newRoles = [...new Set(resolvedRoles.concat(...this.cache.keys()))];
|
|
55
|
+
return this.set(newRoles);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Removes a role (or multiple roles) from the list of roles that can use this emoji.
|
|
60
|
+
* @param {RoleResolvable|RoleResolvable[]|Collection<Snowflake, Role>} roleOrRoles The role or roles to remove
|
|
61
|
+
* @returns {Promise<GuildEmoji>}
|
|
62
|
+
*/
|
|
63
|
+
remove(roleOrRoles) {
|
|
64
|
+
if (!Array.isArray(roleOrRoles) && !(roleOrRoles instanceof Collection)) roleOrRoles = [roleOrRoles];
|
|
65
|
+
|
|
66
|
+
const resolvedRoleIds = [];
|
|
67
|
+
for (const role of roleOrRoles.values()) {
|
|
68
|
+
const roleId = this.guild.roles.resolveId(role);
|
|
69
|
+
if (!roleId) {
|
|
70
|
+
return Promise.reject(new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array or Collection', 'roles', role));
|
|
71
|
+
}
|
|
72
|
+
resolvedRoleIds.push(roleId);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const newRoles = [...this.cache.keys()].filter(id => !resolvedRoleIds.includes(id));
|
|
76
|
+
return this.set(newRoles);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Sets the role(s) that can use this emoji.
|
|
81
|
+
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles The roles or role ids to apply
|
|
82
|
+
* @returns {Promise<GuildEmoji>}
|
|
83
|
+
* @example
|
|
84
|
+
* // Set the emoji's roles to a single role
|
|
85
|
+
* guildEmoji.roles.set(['391156570408615936'])
|
|
86
|
+
* .then(console.log)
|
|
87
|
+
* .catch(console.error);
|
|
88
|
+
* @example
|
|
89
|
+
* // Remove all roles from an emoji
|
|
90
|
+
* guildEmoji.roles.set([])
|
|
91
|
+
* .then(console.log)
|
|
92
|
+
* .catch(console.error);
|
|
93
|
+
*/
|
|
94
|
+
set(roles) {
|
|
95
|
+
return this.emoji.edit({ roles });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
clone() {
|
|
99
|
+
const clone = new this.constructor(this.emoji);
|
|
100
|
+
clone._patch([...this.cache.keys()]);
|
|
101
|
+
return clone;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Patches the roles for this manager's cache
|
|
106
|
+
* @param {Snowflake[]} roles The new roles
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
109
|
+
_patch(roles) {
|
|
110
|
+
this.emoji._roles = roles;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
valueOf() {
|
|
114
|
+
return this.cache;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = GuildEmojiRoleManager;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Routes } = require('discord-api-types/v10');
|
|
4
|
+
const ThreadManager = require('./ThreadManager');
|
|
5
|
+
const { DiscordjsTypeError, ErrorCodes } = require('../errors');
|
|
6
|
+
const MessagePayload = require('../structures/MessagePayload');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Manages API methods for threads in forum channels and stores their cache.
|
|
10
|
+
* @extends {ThreadManager}
|
|
11
|
+
*/
|
|
12
|
+
class GuildForumThreadManager extends ThreadManager {
|
|
13
|
+
/**
|
|
14
|
+
* The channel this Manager belongs to
|
|
15
|
+
* @name GuildForumThreadManager#channel
|
|
16
|
+
* @type {ForumChannel}
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {BaseMessageOptions} GuildForumThreadMessageCreateOptions
|
|
21
|
+
* @property {StickerResolvable} [stickers] The stickers to send with the message
|
|
22
|
+
* @property {BitFieldResolvable} [flags] The flags to send with the message
|
|
23
|
+
* <info>Only `MessageFlags.SuppressEmbeds` and `MessageFlags.SuppressNotifications` can be set.</info>
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Options for creating a thread.
|
|
28
|
+
* @typedef {StartThreadOptions} GuildForumThreadCreateOptions
|
|
29
|
+
* @property {GuildForumThreadMessageCreateOptions|MessagePayload} message The message associated with the thread post
|
|
30
|
+
* @property {Snowflake[]} [appliedTags] The tags to apply to the thread
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new thread in the channel.
|
|
35
|
+
* @param {GuildForumThreadCreateOptions} [options] Options to create a new thread
|
|
36
|
+
* @returns {Promise<ThreadChannel>}
|
|
37
|
+
* @example
|
|
38
|
+
* // Create a new forum post
|
|
39
|
+
* forum.threads
|
|
40
|
+
* .create({
|
|
41
|
+
* name: 'Food Talk',
|
|
42
|
+
* autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
|
|
43
|
+
* message: {
|
|
44
|
+
* content: 'Discuss your favorite food!',
|
|
45
|
+
* },
|
|
46
|
+
* reason: 'Needed a separate thread for food',
|
|
47
|
+
* })
|
|
48
|
+
* .then(threadChannel => console.log(threadChannel))
|
|
49
|
+
* .catch(console.error);
|
|
50
|
+
*/
|
|
51
|
+
async create({
|
|
52
|
+
name,
|
|
53
|
+
autoArchiveDuration = this.channel.defaultAutoArchiveDuration,
|
|
54
|
+
message,
|
|
55
|
+
reason,
|
|
56
|
+
rateLimitPerUser,
|
|
57
|
+
appliedTags,
|
|
58
|
+
} = {}) {
|
|
59
|
+
if (!message) {
|
|
60
|
+
throw new DiscordjsTypeError(ErrorCodes.GuildForumMessageRequired);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { body, files } = await (message instanceof MessagePayload ? message : MessagePayload.create(this, message))
|
|
64
|
+
.resolveBody()
|
|
65
|
+
.resolveFiles();
|
|
66
|
+
|
|
67
|
+
const data = await this.client.rest.post(Routes.threads(this.channel.id), {
|
|
68
|
+
body: {
|
|
69
|
+
name,
|
|
70
|
+
auto_archive_duration: autoArchiveDuration,
|
|
71
|
+
rate_limit_per_user: rateLimitPerUser,
|
|
72
|
+
applied_tags: appliedTags,
|
|
73
|
+
message: body,
|
|
74
|
+
},
|
|
75
|
+
files,
|
|
76
|
+
reason,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return this.client.actions.ThreadCreate.handle(data).thread;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = GuildForumThreadManager;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Collection } = require('@discordjs/collection');
|
|
4
|
+
const { Routes } = require('discord-api-types/v10');
|
|
5
|
+
const CachedManager = require('./CachedManager');
|
|
6
|
+
const { DiscordjsError, ErrorCodes } = require('../errors');
|
|
7
|
+
const Invite = require('../structures/Invite');
|
|
8
|
+
const DataResolver = require('../util/DataResolver');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Manages API methods for GuildInvites and stores their cache.
|
|
12
|
+
* @extends {CachedManager}
|
|
13
|
+
*/
|
|
14
|
+
class GuildInviteManager extends CachedManager {
|
|
15
|
+
constructor(guild, iterable) {
|
|
16
|
+
super(guild.client, Invite, iterable);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The guild this Manager belongs to
|
|
20
|
+
* @type {Guild}
|
|
21
|
+
*/
|
|
22
|
+
this.guild = guild;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The cache of this Manager
|
|
27
|
+
* @type {Collection<string, Invite>}
|
|
28
|
+
* @name GuildInviteManager#cache
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
_add(data, cache) {
|
|
32
|
+
return super._add(data, cache, { id: data.code, extras: [this.guild] });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Data that resolves to give an Invite object. This can be:
|
|
37
|
+
* * An invite code
|
|
38
|
+
* * An invite URL
|
|
39
|
+
* @typedef {string} InviteResolvable
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Data that can be resolved to a channel that an invite can be created on. This can be:
|
|
44
|
+
* * TextChannel
|
|
45
|
+
* * VoiceChannel
|
|
46
|
+
* * NewsChannel
|
|
47
|
+
* * StageChannel
|
|
48
|
+
* * Snowflake
|
|
49
|
+
* @typedef {TextChannel|VoiceChannel|NewsChannel|StageChannel|Snowflake}
|
|
50
|
+
* GuildInvitableChannelResolvable
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Resolves an InviteResolvable to an Invite object.
|
|
55
|
+
* @method resolve
|
|
56
|
+
* @memberof GuildInviteManager
|
|
57
|
+
* @instance
|
|
58
|
+
* @param {InviteResolvable} invite The invite resolvable to resolve
|
|
59
|
+
* @returns {?Invite}
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Resolves an InviteResolvable to an invite code string.
|
|
64
|
+
* @method resolveId
|
|
65
|
+
* @memberof GuildInviteManager
|
|
66
|
+
* @instance
|
|
67
|
+
* @param {InviteResolvable} invite The invite resolvable to resolve
|
|
68
|
+
* @returns {?string}
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Options used to fetch a single invite from a guild.
|
|
73
|
+
* @typedef {Object} FetchInviteOptions
|
|
74
|
+
* @property {InviteResolvable} code The invite to fetch
|
|
75
|
+
* @property {boolean} [cache=true] Whether or not to cache the fetched invite
|
|
76
|
+
* @property {boolean} [force=false] Whether to skip the cache check and request the API
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Options used to fetch all invites from a guild.
|
|
81
|
+
* @typedef {Object} FetchInvitesOptions
|
|
82
|
+
* @property {GuildInvitableChannelResolvable} [channelId]
|
|
83
|
+
* The channel to fetch all invites from
|
|
84
|
+
* @property {boolean} [cache=true] Whether or not to cache the fetched invites
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Fetches invite(s) from Discord.
|
|
89
|
+
* @param {InviteResolvable|FetchInviteOptions|FetchInvitesOptions} [options] Options for fetching guild invite(s)
|
|
90
|
+
* @returns {Promise<Invite|Collection<string, Invite>>}
|
|
91
|
+
* @example
|
|
92
|
+
* // Fetch all invites from a guild
|
|
93
|
+
* guild.invites.fetch()
|
|
94
|
+
* .then(console.log)
|
|
95
|
+
* .catch(console.error);
|
|
96
|
+
* @example
|
|
97
|
+
* // Fetch all invites from a guild without caching
|
|
98
|
+
* guild.invites.fetch({ cache: false })
|
|
99
|
+
* .then(console.log)
|
|
100
|
+
* .catch(console.error);
|
|
101
|
+
* @example
|
|
102
|
+
* // Fetch all invites from a channel
|
|
103
|
+
* guild.invites.fetch({ channelId: '222197033908436994' })
|
|
104
|
+
* .then(console.log)
|
|
105
|
+
* .catch(console.error);
|
|
106
|
+
* @example
|
|
107
|
+
* // Fetch a single invite
|
|
108
|
+
* guild.invites.fetch('bRCvFy9')
|
|
109
|
+
* .then(console.log)
|
|
110
|
+
* .catch(console.error);
|
|
111
|
+
* @example
|
|
112
|
+
* // Fetch a single invite without checking cache
|
|
113
|
+
* guild.invites.fetch({ code: 'bRCvFy9', force: true })
|
|
114
|
+
* .then(console.log)
|
|
115
|
+
* .catch(console.error)
|
|
116
|
+
* @example
|
|
117
|
+
* // Fetch a single invite without caching
|
|
118
|
+
* guild.invites.fetch({ code: 'bRCvFy9', cache: false })
|
|
119
|
+
* .then(console.log)
|
|
120
|
+
* .catch(console.error);
|
|
121
|
+
*/
|
|
122
|
+
fetch(options) {
|
|
123
|
+
if (!options) return this._fetchMany();
|
|
124
|
+
if (typeof options === 'string') {
|
|
125
|
+
const code = DataResolver.resolveInviteCode(options);
|
|
126
|
+
if (!code) return Promise.reject(new DiscordjsError(ErrorCodes.InviteResolveCode));
|
|
127
|
+
return this._fetchSingle({ code, cache: true });
|
|
128
|
+
}
|
|
129
|
+
if (!options.code) {
|
|
130
|
+
if (options.channelId) {
|
|
131
|
+
const id = this.guild.channels.resolveId(options.channelId);
|
|
132
|
+
if (!id) return Promise.reject(new DiscordjsError(ErrorCodes.GuildChannelResolve));
|
|
133
|
+
return this._fetchChannelMany(id, options.cache);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if ('cache' in options) return this._fetchMany(options.cache);
|
|
137
|
+
return Promise.reject(new DiscordjsError(ErrorCodes.InviteResolveCode));
|
|
138
|
+
}
|
|
139
|
+
return this._fetchSingle({
|
|
140
|
+
...options,
|
|
141
|
+
code: DataResolver.resolveInviteCode(options.code),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async _fetchSingle({ code, cache, force = false }) {
|
|
146
|
+
if (!force) {
|
|
147
|
+
const existing = this.cache.get(code);
|
|
148
|
+
if (existing) return existing;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const invites = await this._fetchMany(cache);
|
|
152
|
+
const invite = invites.get(code);
|
|
153
|
+
if (!invite) throw new DiscordjsError(ErrorCodes.InviteNotFound);
|
|
154
|
+
return invite;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async _fetchMany(cache) {
|
|
158
|
+
const data = await this.client.rest.get(Routes.guildInvites(this.guild.id));
|
|
159
|
+
return data.reduce((col, invite) => col.set(invite.code, this._add(invite, cache)), new Collection());
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async _fetchChannelMany(channelId, cache) {
|
|
163
|
+
const data = await this.client.rest.get(Routes.channelInvites(channelId));
|
|
164
|
+
return data.reduce((col, invite) => col.set(invite.code, this._add(invite, cache)), new Collection());
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Create an invite to the guild from the provided channel.
|
|
169
|
+
* @param {GuildInvitableChannelResolvable} channel The options for creating the invite from a channel.
|
|
170
|
+
* @param {InviteCreateOptions} [options={}] The options for creating the invite from a channel.
|
|
171
|
+
* @returns {Promise<Invite>}
|
|
172
|
+
* @example
|
|
173
|
+
* // Create an invite to a selected channel
|
|
174
|
+
* guild.invites.create('599942732013764608')
|
|
175
|
+
* .then(console.log)
|
|
176
|
+
* .catch(console.error);
|
|
177
|
+
*/
|
|
178
|
+
async create(
|
|
179
|
+
channel,
|
|
180
|
+
{ temporary, maxAge, maxUses, unique, targetUser, targetApplication, targetType, reason } = {},
|
|
181
|
+
) {
|
|
182
|
+
const id = this.guild.channels.resolveId(channel);
|
|
183
|
+
if (!id) throw new DiscordjsError(ErrorCodes.GuildChannelResolve);
|
|
184
|
+
|
|
185
|
+
const invite = await this.client.rest.post(Routes.channelInvites(id), {
|
|
186
|
+
body: {
|
|
187
|
+
temporary,
|
|
188
|
+
max_age: maxAge,
|
|
189
|
+
max_uses: maxUses,
|
|
190
|
+
unique,
|
|
191
|
+
target_user_id: this.client.users.resolveId(targetUser),
|
|
192
|
+
target_application_id: targetApplication?.id ?? targetApplication?.applicationId ?? targetApplication,
|
|
193
|
+
target_type: targetType,
|
|
194
|
+
},
|
|
195
|
+
reason,
|
|
196
|
+
});
|
|
197
|
+
return new Invite(this.client, invite);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Deletes an invite.
|
|
202
|
+
* @param {InviteResolvable} invite The invite to delete
|
|
203
|
+
* @param {string} [reason] Reason for deleting the invite
|
|
204
|
+
* @returns {Promise<void>}
|
|
205
|
+
*/
|
|
206
|
+
async delete(invite, reason) {
|
|
207
|
+
const code = DataResolver.resolveInviteCode(invite);
|
|
208
|
+
|
|
209
|
+
await this.client.rest.delete(Routes.invite(code), { reason });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
module.exports = GuildInviteManager;
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const process = require('node:process');
|
|
4
|
+
const { setTimeout, clearTimeout } = require('node:timers');
|
|
5
|
+
const { Collection } = require('@discordjs/collection');
|
|
6
|
+
const { makeURLSearchParams } = require('@discordjs/rest');
|
|
7
|
+
const { Routes } = require('discord-api-types/v10');
|
|
8
|
+
const CachedManager = require('./CachedManager');
|
|
9
|
+
const { Guild } = require('../structures/Guild');
|
|
10
|
+
const GuildChannel = require('../structures/GuildChannel');
|
|
11
|
+
const GuildEmoji = require('../structures/GuildEmoji');
|
|
12
|
+
const { GuildMember } = require('../structures/GuildMember');
|
|
13
|
+
const Invite = require('../structures/Invite');
|
|
14
|
+
const OAuth2Guild = require('../structures/OAuth2Guild');
|
|
15
|
+
const { Role } = require('../structures/Role');
|
|
16
|
+
const DataResolver = require('../util/DataResolver');
|
|
17
|
+
const Events = require('../util/Events');
|
|
18
|
+
const PermissionsBitField = require('../util/PermissionsBitField');
|
|
19
|
+
const SystemChannelFlagsBitField = require('../util/SystemChannelFlagsBitField');
|
|
20
|
+
const { resolveColor } = require('../util/Util');
|
|
21
|
+
|
|
22
|
+
let cacheWarningEmitted = false;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Manages API methods for Guilds and stores their cache.
|
|
26
|
+
* @extends {CachedManager}
|
|
27
|
+
*/
|
|
28
|
+
class GuildManager extends CachedManager {
|
|
29
|
+
constructor(client, iterable) {
|
|
30
|
+
super(client, Guild, iterable);
|
|
31
|
+
if (!cacheWarningEmitted && this._cache.constructor.name !== 'Collection') {
|
|
32
|
+
cacheWarningEmitted = true;
|
|
33
|
+
process.emitWarning(
|
|
34
|
+
`Overriding the cache handling for ${this.constructor.name} is unsupported and breaks functionality.`,
|
|
35
|
+
'UnsupportedCacheOverwriteWarning',
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The cache of this Manager
|
|
42
|
+
* @type {Collection<Snowflake, Guild>}
|
|
43
|
+
* @name GuildManager#cache
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Data that resolves to give a Guild object. This can be:
|
|
48
|
+
* * A Guild object
|
|
49
|
+
* * A GuildChannel object
|
|
50
|
+
* * A GuildEmoji object
|
|
51
|
+
* * A Role object
|
|
52
|
+
* * A Snowflake
|
|
53
|
+
* * An Invite object
|
|
54
|
+
* @typedef {Guild|GuildChannel|GuildMember|GuildEmoji|Role|Snowflake|Invite} GuildResolvable
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Partial data for a Role.
|
|
59
|
+
* @typedef {Object} PartialRoleData
|
|
60
|
+
* @property {Snowflake|number} [id] The role's id, used to set channel overrides.
|
|
61
|
+
* This is a placeholder and will be replaced by the API after consumption
|
|
62
|
+
* @property {string} [name] The name of the role
|
|
63
|
+
* @property {ColorResolvable} [color] The color of the role, either a hex string or a base 10 number
|
|
64
|
+
* @property {boolean} [hoist] Whether the role should be hoisted
|
|
65
|
+
* @property {number} [position] The position of the role
|
|
66
|
+
* @property {PermissionResolvable} [permissions] The permissions of the role
|
|
67
|
+
* @property {boolean} [mentionable] Whether the role should be mentionable
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Partial overwrite data.
|
|
72
|
+
* @typedef {Object} PartialOverwriteData
|
|
73
|
+
* @property {Snowflake|number} id The id of the {@link Role} or {@link User} this overwrite belongs to
|
|
74
|
+
* @property {OverwriteType} [type] The type of this overwrite
|
|
75
|
+
* @property {PermissionResolvable} [allow] The permissions to allow
|
|
76
|
+
* @property {PermissionResolvable} [deny] The permissions to deny
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Partial data for a Channel.
|
|
81
|
+
* @typedef {Object} PartialChannelData
|
|
82
|
+
* @property {Snowflake|number} [id] The channel's id, used to set its parent.
|
|
83
|
+
* This is a placeholder and will be replaced by the API after consumption
|
|
84
|
+
* @property {Snowflake|number} [parentId] The parent id for this channel
|
|
85
|
+
* @property {ChannelType.GuildText|ChannelType.GuildVoice|ChannelType.GuildCategory} [type] The type of the channel
|
|
86
|
+
* @property {string} name The name of the channel
|
|
87
|
+
* @property {?string} [topic] The topic of the text channel
|
|
88
|
+
* @property {boolean} [nsfw] Whether the channel is NSFW
|
|
89
|
+
* @property {number} [bitrate] The bitrate of the voice channel
|
|
90
|
+
* @property {number} [userLimit] The user limit of the channel
|
|
91
|
+
* @property {?string} [rtcRegion] The RTC region of the channel
|
|
92
|
+
* @property {VideoQualityMode} [videoQualityMode] The camera video quality mode of the channel
|
|
93
|
+
* @property {PartialOverwriteData[]} [permissionOverwrites]
|
|
94
|
+
* Overwrites of the channel
|
|
95
|
+
* @property {number} [rateLimitPerUser] The rate limit per user (slowmode) of the channel in seconds
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Resolves a GuildResolvable to a Guild object.
|
|
100
|
+
* @method resolve
|
|
101
|
+
* @memberof GuildManager
|
|
102
|
+
* @instance
|
|
103
|
+
* @param {GuildResolvable} guild The guild resolvable to identify
|
|
104
|
+
* @returns {?Guild}
|
|
105
|
+
*/
|
|
106
|
+
resolve(guild) {
|
|
107
|
+
if (
|
|
108
|
+
guild instanceof GuildChannel ||
|
|
109
|
+
guild instanceof GuildMember ||
|
|
110
|
+
guild instanceof GuildEmoji ||
|
|
111
|
+
guild instanceof Role ||
|
|
112
|
+
(guild instanceof Invite && guild.guild)
|
|
113
|
+
) {
|
|
114
|
+
return super.resolve(guild.guild);
|
|
115
|
+
}
|
|
116
|
+
return super.resolve(guild);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Resolves a {@link GuildResolvable} to a {@link Guild} id string.
|
|
121
|
+
* @method resolveId
|
|
122
|
+
* @memberof GuildManager
|
|
123
|
+
* @instance
|
|
124
|
+
* @param {GuildResolvable} guild The guild resolvable to identify
|
|
125
|
+
* @returns {?Snowflake}
|
|
126
|
+
*/
|
|
127
|
+
resolveId(guild) {
|
|
128
|
+
if (
|
|
129
|
+
guild instanceof GuildChannel ||
|
|
130
|
+
guild instanceof GuildMember ||
|
|
131
|
+
guild instanceof GuildEmoji ||
|
|
132
|
+
guild instanceof Role ||
|
|
133
|
+
(guild instanceof Invite && guild.guild)
|
|
134
|
+
) {
|
|
135
|
+
return super.resolveId(guild.guild.id);
|
|
136
|
+
}
|
|
137
|
+
return super.resolveId(guild);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Options used to create a guild.
|
|
142
|
+
* @typedef {Object} GuildCreateOptions
|
|
143
|
+
* @property {string} name The name of the guild
|
|
144
|
+
* @property {?(BufferResolvable|Base64Resolvable)} [icon=null] The icon for the guild
|
|
145
|
+
* @property {GuildVerificationLevel} [verificationLevel] The verification level for the guild
|
|
146
|
+
* @property {GuildDefaultMessageNotifications} [defaultMessageNotifications] The default message notifications
|
|
147
|
+
* for the guild
|
|
148
|
+
* @property {GuildExplicitContentFilter} [explicitContentFilter] The explicit content filter level for the guild
|
|
149
|
+
* @property {PartialRoleData[]} [roles=[]] The roles for this guild,
|
|
150
|
+
* @property {PartialChannelData[]} [channels=[]] The channels for this guild
|
|
151
|
+
* @property {Snowflake|number} [afkChannelId] The AFK channel's id
|
|
152
|
+
* @property {number} [afkTimeout] The AFK timeout in seconds
|
|
153
|
+
* the first element of this array is used to change properties of the guild's everyone role.
|
|
154
|
+
* @property {Snowflake|number} [systemChannelId] The system channel's id
|
|
155
|
+
* @property {SystemChannelFlagsResolvable} [systemChannelFlags] The flags of the system channel
|
|
156
|
+
*/
|
|
157
|
+
/* eslint-enable max-len */
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Creates a guild.
|
|
161
|
+
* <warn>This is only available to bots in fewer than 10 guilds.</warn>
|
|
162
|
+
* @param {GuildCreateOptions} options Options for creating the guild
|
|
163
|
+
* @returns {Promise<Guild>} The guild that was created
|
|
164
|
+
*/
|
|
165
|
+
async create({
|
|
166
|
+
name,
|
|
167
|
+
icon = null,
|
|
168
|
+
verificationLevel,
|
|
169
|
+
defaultMessageNotifications,
|
|
170
|
+
explicitContentFilter,
|
|
171
|
+
roles = [],
|
|
172
|
+
channels = [],
|
|
173
|
+
afkChannelId,
|
|
174
|
+
afkTimeout,
|
|
175
|
+
systemChannelId,
|
|
176
|
+
systemChannelFlags,
|
|
177
|
+
}) {
|
|
178
|
+
const data = await this.client.rest.post(Routes.guilds(), {
|
|
179
|
+
body: {
|
|
180
|
+
name,
|
|
181
|
+
icon: icon && (await DataResolver.resolveImage(icon)),
|
|
182
|
+
verification_level: verificationLevel,
|
|
183
|
+
default_message_notifications: defaultMessageNotifications,
|
|
184
|
+
explicit_content_filter: explicitContentFilter,
|
|
185
|
+
roles: roles.map(({ color, permissions, ...options }) => ({
|
|
186
|
+
...options,
|
|
187
|
+
color: color && resolveColor(color),
|
|
188
|
+
permissions: permissions === undefined ? undefined : PermissionsBitField.resolve(permissions).toString(),
|
|
189
|
+
})),
|
|
190
|
+
channels: channels.map(
|
|
191
|
+
({
|
|
192
|
+
parentId,
|
|
193
|
+
userLimit,
|
|
194
|
+
rtcRegion,
|
|
195
|
+
videoQualityMode,
|
|
196
|
+
permissionOverwrites,
|
|
197
|
+
rateLimitPerUser,
|
|
198
|
+
...options
|
|
199
|
+
}) => ({
|
|
200
|
+
...options,
|
|
201
|
+
parent_id: parentId,
|
|
202
|
+
user_limit: userLimit,
|
|
203
|
+
rtc_region: rtcRegion,
|
|
204
|
+
video_quality_mode: videoQualityMode,
|
|
205
|
+
permission_overwrites: permissionOverwrites?.map(({ allow, deny, ...permissionOverwriteOptions }) => ({
|
|
206
|
+
...permissionOverwriteOptions,
|
|
207
|
+
allow: allow === undefined ? undefined : PermissionsBitField.resolve(allow).toString(),
|
|
208
|
+
deny: deny === undefined ? undefined : PermissionsBitField.resolve(deny).toString(),
|
|
209
|
+
})),
|
|
210
|
+
rate_limit_per_user: rateLimitPerUser,
|
|
211
|
+
}),
|
|
212
|
+
),
|
|
213
|
+
afk_channel_id: afkChannelId,
|
|
214
|
+
afk_timeout: afkTimeout,
|
|
215
|
+
system_channel_id: systemChannelId,
|
|
216
|
+
system_channel_flags:
|
|
217
|
+
systemChannelFlags === undefined ? undefined : SystemChannelFlagsBitField.resolve(systemChannelFlags),
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
return (
|
|
222
|
+
this.client.guilds.cache.get(data.id) ??
|
|
223
|
+
new Promise(resolve => {
|
|
224
|
+
const handleGuild = guild => {
|
|
225
|
+
if (guild.id === data.id) {
|
|
226
|
+
clearTimeout(timeout);
|
|
227
|
+
this.client.decrementMaxListeners();
|
|
228
|
+
resolve(guild);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
this.client.incrementMaxListeners();
|
|
232
|
+
this.client.once(Events.GuildCreate, handleGuild);
|
|
233
|
+
|
|
234
|
+
const timeout = setTimeout(() => {
|
|
235
|
+
this.client.removeListener(Events.GuildCreate, handleGuild);
|
|
236
|
+
this.client.decrementMaxListeners();
|
|
237
|
+
resolve(this.client.guilds._add(data));
|
|
238
|
+
}, 10_000).unref();
|
|
239
|
+
})
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Options used to fetch a single guild.
|
|
245
|
+
* @typedef {BaseFetchOptions} FetchGuildOptions
|
|
246
|
+
* @property {GuildResolvable} guild The guild to fetch
|
|
247
|
+
* @property {boolean} [withCounts=true] Whether the approximate member and presence counts should be returned
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Options used to fetch multiple guilds.
|
|
252
|
+
* @typedef {Object} FetchGuildsOptions
|
|
253
|
+
* @property {Snowflake} [before] Get guilds before this guild id
|
|
254
|
+
* @property {Snowflake} [after] Get guilds after this guild id
|
|
255
|
+
* @property {number} [limit] Maximum number of guilds to request (1-200)
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Obtains one or multiple guilds from Discord, or the guild cache if it's already available.
|
|
260
|
+
* @param {GuildResolvable|FetchGuildOptions|FetchGuildsOptions} [options] The guild's id or options
|
|
261
|
+
* @returns {Promise<Guild|Collection<Snowflake, OAuth2Guild>>}
|
|
262
|
+
*/
|
|
263
|
+
async fetch(options = {}) {
|
|
264
|
+
const id = this.resolveId(options) ?? this.resolveId(options.guild);
|
|
265
|
+
|
|
266
|
+
if (id) {
|
|
267
|
+
if (!options.force) {
|
|
268
|
+
const existing = this.cache.get(id);
|
|
269
|
+
if (existing) return existing;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const data = await this.client.rest.get(Routes.guild(id), {
|
|
273
|
+
query: makeURLSearchParams({ with_counts: options.withCounts ?? true }),
|
|
274
|
+
});
|
|
275
|
+
return this._add(data, options.cache);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const data = await this.client.rest.get(Routes.userGuilds(), { query: makeURLSearchParams(options) });
|
|
279
|
+
return data.reduce((coll, guild) => coll.set(guild.id, new OAuth2Guild(this.client, guild)), new Collection());
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
module.exports = GuildManager;
|