@ovencord/discord.js 14.16.3
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 +148 -0
- package/package.json +73 -0
- package/src/client/Client.ts +967 -0
- package/src/client/actions/Action.ts +141 -0
- package/src/client/actions/ActionsManager.ts +138 -0
- package/src/client/actions/ChannelCreate.ts +21 -0
- package/src/client/actions/ChannelDelete.ts +20 -0
- package/src/client/actions/ChannelUpdate.ts +38 -0
- package/src/client/actions/GuildChannelsPositionUpdate.ts +17 -0
- package/src/client/actions/GuildEmojiCreate.ts +17 -0
- package/src/client/actions/GuildEmojiDelete.ts +16 -0
- package/src/client/actions/GuildEmojiUpdate.ts +17 -0
- package/src/client/actions/GuildEmojisUpdate.ts +30 -0
- package/src/client/actions/GuildMemberRemove.ts +29 -0
- package/src/client/actions/GuildMemberUpdate.ts +41 -0
- package/src/client/actions/GuildRoleCreate.ts +23 -0
- package/src/client/actions/GuildRoleDelete.ts +26 -0
- package/src/client/actions/GuildRolesPositionUpdate.ts +17 -0
- package/src/client/actions/GuildScheduledEventDelete.ts +28 -0
- package/src/client/actions/GuildScheduledEventUserAdd.ts +29 -0
- package/src/client/actions/GuildScheduledEventUserRemove.ts +29 -0
- package/src/client/actions/GuildSoundboardSoundDelete.ts +26 -0
- package/src/client/actions/GuildStickerCreate.ts +17 -0
- package/src/client/actions/GuildStickerDelete.ts +16 -0
- package/src/client/actions/GuildStickerUpdate.ts +17 -0
- package/src/client/actions/GuildStickersUpdate.ts +30 -0
- package/src/client/actions/GuildUpdate.ts +30 -0
- package/src/client/actions/InteractionCreate.ts +104 -0
- package/src/client/actions/MessageCreate.ts +38 -0
- package/src/client/actions/MessageDelete.ts +29 -0
- package/src/client/actions/MessageDeleteBulk.ts +45 -0
- package/src/client/actions/MessagePollVoteAdd.ts +37 -0
- package/src/client/actions/MessagePollVoteRemove.ts +35 -0
- package/src/client/actions/MessageReactionAdd.ts +68 -0
- package/src/client/actions/MessageReactionRemove.ts +47 -0
- package/src/client/actions/MessageReactionRemoveAll.ts +30 -0
- package/src/client/actions/MessageReactionRemoveEmoji.ts +25 -0
- package/src/client/actions/MessageUpdate.ts +22 -0
- package/src/client/actions/StageInstanceCreate.ts +25 -0
- package/src/client/actions/StageInstanceDelete.ts +28 -0
- package/src/client/actions/StageInstanceUpdate.ts +27 -0
- package/src/client/actions/ThreadCreate.ts +22 -0
- package/src/client/actions/ThreadMembersUpdate.ts +45 -0
- package/src/client/actions/TypingStart.ts +26 -0
- package/src/client/actions/UserUpdate.ts +33 -0
- package/src/client/voice/ClientVoiceManager.ts +46 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts +19 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.ts +17 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.ts +18 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.ts +21 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.ts +20 -0
- package/src/client/websocket/handlers/CHANNEL_CREATE.ts +4 -0
- package/src/client/websocket/handlers/CHANNEL_DELETE.ts +4 -0
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.ts +22 -0
- package/src/client/websocket/handlers/CHANNEL_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/ENTITLEMENT_CREATE.ts +14 -0
- package/src/client/websocket/handlers/ENTITLEMENT_DELETE.ts +18 -0
- package/src/client/websocket/handlers/ENTITLEMENT_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.ts +19 -0
- package/src/client/websocket/handlers/GUILD_BAN_ADD.ts +15 -0
- package/src/client/websocket/handlers/GUILD_BAN_REMOVE.ts +20 -0
- package/src/client/websocket/handlers/GUILD_CREATE.ts +34 -0
- package/src/client/websocket/handlers/GUILD_DELETE.ts +36 -0
- package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.ts +15 -0
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.ts +40 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.ts +17 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_ROLE_CREATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_ROLE_DELETE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.ts +21 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.ts +17 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.ts +19 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.ts +24 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.ts +18 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.ts +20 -0
- package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/INTERACTION_CREATE.ts +4 -0
- package/src/client/websocket/handlers/INVITE_CREATE.ts +20 -0
- package/src/client/websocket/handlers/INVITE_DELETE.ts +23 -0
- package/src/client/websocket/handlers/MESSAGE_CREATE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/PRESENCE_UPDATE.ts +42 -0
- package/src/client/websocket/handlers/RATE_LIMITED.ts +23 -0
- package/src/client/websocket/handlers/READY.ts +29 -0
- package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.ts +24 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.ts +4 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.ts +4 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.ts +14 -0
- package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.ts +16 -0
- package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/THREAD_CREATE.ts +4 -0
- package/src/client/websocket/handlers/THREAD_DELETE.ts +17 -0
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.ts +50 -0
- package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.ts +25 -0
- package/src/client/websocket/handlers/THREAD_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/TYPING_START.ts +4 -0
- package/src/client/websocket/handlers/USER_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.ts +16 -0
- package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.ts +5 -0
- package/src/client/websocket/handlers/VOICE_STATE_UPDATE.ts +37 -0
- package/src/client/websocket/handlers/WEBHOOKS_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/index.ts +74 -0
- package/src/errors/DJSError.ts +50 -0
- package/src/errors/ErrorCodes.ts +277 -0
- package/src/errors/Messages.ts +155 -0
- package/src/errors/index.ts +6 -0
- package/src/index.ts +241 -0
- package/src/managers/ApplicationCommandManager.ts +303 -0
- package/src/managers/ApplicationCommandPermissionsManager.ts +453 -0
- package/src/managers/ApplicationEmojiManager.ts +149 -0
- package/src/managers/AutoModerationRuleManager.ts +307 -0
- package/src/managers/BaseManager.ts +13 -0
- package/src/managers/CachedManager.ts +56 -0
- package/src/managers/CategoryChannelChildManager.ts +81 -0
- package/src/managers/ChannelManager.ts +194 -0
- package/src/managers/DMMessageManager.ts +15 -0
- package/src/managers/DataManager.ts +38 -0
- package/src/managers/EntitlementManager.ts +182 -0
- package/src/managers/GuildApplicationCommandManager.ts +29 -0
- package/src/managers/GuildBanManager.ts +221 -0
- package/src/managers/GuildChannelManager.ts +552 -0
- package/src/managers/GuildEmojiManager.ts +262 -0
- package/src/managers/GuildEmojiRoleManager.ts +134 -0
- package/src/managers/GuildForumThreadManager.ts +84 -0
- package/src/managers/GuildInviteManager.ts +236 -0
- package/src/managers/GuildManager.ts +265 -0
- package/src/managers/GuildMemberManager.ts +619 -0
- package/src/managers/GuildMemberRoleManager.ts +230 -0
- package/src/managers/GuildMessageManager.ts +31 -0
- package/src/managers/GuildScheduledEventManager.ts +330 -0
- package/src/managers/GuildSoundboardSoundManager.ts +157 -0
- package/src/managers/GuildStickerManager.ts +192 -0
- package/src/managers/GuildTextThreadManager.ts +91 -0
- package/src/managers/MessageManager.ts +352 -0
- package/src/managers/PartialGroupDMMessageManager.ts +15 -0
- package/src/managers/PermissionOverwriteManager.ts +174 -0
- package/src/managers/PollAnswerVoterManager.ts +59 -0
- package/src/managers/PresenceManager.ts +60 -0
- package/src/managers/ReactionManager.ts +72 -0
- package/src/managers/ReactionUserManager.ts +82 -0
- package/src/managers/RoleManager.ts +432 -0
- package/src/managers/StageInstanceManager.ts +166 -0
- package/src/managers/SubscriptionManager.ts +83 -0
- package/src/managers/ThreadManager.ts +210 -0
- package/src/managers/ThreadMemberManager.ts +194 -0
- package/src/managers/UserManager.ts +139 -0
- package/src/managers/VoiceStateManager.ts +61 -0
- package/src/sharding/Shard.ts +513 -0
- package/src/sharding/ShardClientUtil.ts +293 -0
- package/src/sharding/ShardingManager.ts +374 -0
- package/src/structures/ActionRow.ts +31 -0
- package/src/structures/AnnouncementChannel.ts +25 -0
- package/src/structures/AnonymousGuild.ts +110 -0
- package/src/structures/ApplicationCommand.ts +675 -0
- package/src/structures/ApplicationEmoji.ts +189 -0
- package/src/structures/ApplicationRoleConnectionMetadata.ts +54 -0
- package/src/structures/Attachment.ts +189 -0
- package/src/structures/AuthorizingIntegrationOwners.ts +63 -0
- package/src/structures/AutoModerationActionExecution.ts +138 -0
- package/src/structures/AutoModerationRule.ts +325 -0
- package/src/structures/AutocompleteInteraction.ts +115 -0
- package/src/structures/Base.ts +37 -0
- package/src/structures/BaseChannel.ts +188 -0
- package/src/structures/BaseGuild.ts +134 -0
- package/src/structures/BaseGuildEmoji.ts +113 -0
- package/src/structures/BaseGuildTextChannel.ts +230 -0
- package/src/structures/BaseGuildVoiceChannel.ts +270 -0
- package/src/structures/BaseInteraction.ts +393 -0
- package/src/structures/BaseInvite.ts +192 -0
- package/src/structures/BaseSelectMenuComponent.ts +58 -0
- package/src/structures/ButtonComponent.ts +68 -0
- package/src/structures/ButtonInteraction.ts +8 -0
- package/src/structures/CategoryChannel.ts +46 -0
- package/src/structures/ChannelSelectMenuComponent.ts +18 -0
- package/src/structures/ChannelSelectMenuInteraction.ts +34 -0
- package/src/structures/ChatInputCommandInteraction.ts +43 -0
- package/src/structures/ClientApplication.ts +470 -0
- package/src/structures/ClientPresence.ts +87 -0
- package/src/structures/ClientUser.ts +219 -0
- package/src/structures/CommandInteraction.ts +193 -0
- package/src/structures/CommandInteractionOptionResolver.ts +336 -0
- package/src/structures/Component.ts +59 -0
- package/src/structures/ContainerComponent.ts +63 -0
- package/src/structures/ContextMenuCommandInteraction.ts +68 -0
- package/src/structures/DMChannel.ts +148 -0
- package/src/structures/DirectoryChannel.ts +40 -0
- package/src/structures/Embed.ts +251 -0
- package/src/structures/Emoji.ts +61 -0
- package/src/structures/Entitlement.ts +206 -0
- package/src/structures/FileComponent.ts +41 -0
- package/src/structures/ForumChannel.ts +31 -0
- package/src/structures/GroupDMInvite.ts +34 -0
- package/src/structures/Guild.ts +1605 -0
- package/src/structures/GuildAuditLogs.ts +99 -0
- package/src/structures/GuildAuditLogsEntry.ts +557 -0
- package/src/structures/GuildBan.ts +65 -0
- package/src/structures/GuildChannel.ts +515 -0
- package/src/structures/GuildEmoji.ts +159 -0
- package/src/structures/GuildInvite.ts +233 -0
- package/src/structures/GuildMember.ts +643 -0
- package/src/structures/GuildOnboarding.ts +73 -0
- package/src/structures/GuildOnboardingPrompt.ts +93 -0
- package/src/structures/GuildOnboardingPromptOption.ts +100 -0
- package/src/structures/GuildPreview.ts +218 -0
- package/src/structures/GuildPreviewEmoji.ts +28 -0
- package/src/structures/GuildScheduledEvent.ts +593 -0
- package/src/structures/GuildTemplate.ts +229 -0
- package/src/structures/Integration.ts +257 -0
- package/src/structures/IntegrationApplication.ts +84 -0
- package/src/structures/InteractionCallback.ts +86 -0
- package/src/structures/InteractionCallbackResource.ts +57 -0
- package/src/structures/InteractionCallbackResponse.ts +35 -0
- package/src/structures/InteractionCollector.ts +260 -0
- package/src/structures/InteractionWebhook.ts +65 -0
- package/src/structures/InviteGuild.ts +22 -0
- package/src/structures/LabelComponent.ts +51 -0
- package/src/structures/MediaChannel.ts +8 -0
- package/src/structures/MediaGalleryComponent.ts +31 -0
- package/src/structures/MediaGalleryItem.ts +54 -0
- package/src/structures/MentionableSelectMenuComponent.ts +8 -0
- package/src/structures/MentionableSelectMenuInteraction.ts +76 -0
- package/src/structures/Message.ts +1202 -0
- package/src/structures/MessageCollector.ts +155 -0
- package/src/structures/MessageComponentInteraction.ts +132 -0
- package/src/structures/MessageContextMenuCommandInteraction.ts +18 -0
- package/src/structures/MessageMentions.ts +327 -0
- package/src/structures/MessagePayload.ts +325 -0
- package/src/structures/MessageReaction.ts +219 -0
- package/src/structures/ModalComponentResolver.ts +237 -0
- package/src/structures/ModalSubmitInteraction.ts +260 -0
- package/src/structures/OAuth2Guild.ts +30 -0
- package/src/structures/PartialGroupDMChannel.ts +151 -0
- package/src/structures/PermissionOverwrites.ts +222 -0
- package/src/structures/Poll.ts +195 -0
- package/src/structures/PollAnswer.ts +100 -0
- package/src/structures/Presence.ts +448 -0
- package/src/structures/PrimaryEntryPointCommandInteraction.ts +8 -0
- package/src/structures/ReactionCollector.ts +245 -0
- package/src/structures/ReactionEmoji.ts +30 -0
- package/src/structures/Role.ts +543 -0
- package/src/structures/RoleSelectMenuComponent.ts +8 -0
- package/src/structures/RoleSelectMenuInteraction.ts +34 -0
- package/src/structures/SKU.ts +62 -0
- package/src/structures/SectionComponent.ts +44 -0
- package/src/structures/SeparatorComponent.ts +29 -0
- package/src/structures/SoundboardSound.ts +176 -0
- package/src/structures/StageChannel.ts +118 -0
- package/src/structures/StageInstance.ts +173 -0
- package/src/structures/Sticker.ts +300 -0
- package/src/structures/StickerPack.ts +111 -0
- package/src/structures/StringSelectMenuComponent.ts +18 -0
- package/src/structures/StringSelectMenuInteraction.ts +21 -0
- package/src/structures/Subscription.ts +138 -0
- package/src/structures/Team.ts +131 -0
- package/src/structures/TeamMember.ts +77 -0
- package/src/structures/TextChannel.ts +33 -0
- package/src/structures/TextDisplayComponent.ts +18 -0
- package/src/structures/TextInputComponent.ts +28 -0
- package/src/structures/ThreadChannel.ts +680 -0
- package/src/structures/ThreadMember.ts +125 -0
- package/src/structures/ThreadOnlyChannel.ts +276 -0
- package/src/structures/ThumbnailComponent.ts +51 -0
- package/src/structures/Typing.ts +81 -0
- package/src/structures/UnfurledMediaItem.ts +33 -0
- package/src/structures/User.ts +511 -0
- package/src/structures/UserContextMenuCommandInteraction.ts +28 -0
- package/src/structures/UserSelectMenuComponent.ts +8 -0
- package/src/structures/UserSelectMenuInteraction.ts +54 -0
- package/src/structures/VoiceChannel.ts +119 -0
- package/src/structures/VoiceChannelEffect.ts +92 -0
- package/src/structures/VoiceRegion.ts +52 -0
- package/src/structures/VoiceState.ts +346 -0
- package/src/structures/Webhook.ts +526 -0
- package/src/structures/WelcomeChannel.ts +67 -0
- package/src/structures/WelcomeScreen.ts +53 -0
- package/src/structures/Widget.ts +110 -0
- package/src/structures/WidgetMember.ts +124 -0
- package/src/structures/interfaces/Application.ts +179 -0
- package/src/structures/interfaces/Collector.ts +372 -0
- package/src/structures/interfaces/InteractionResponses.ts +384 -0
- package/src/structures/interfaces/TextBasedChannel.ts +430 -0
- package/src/util/APITypes.ts +690 -0
- package/src/util/ActivityFlagsBitField.ts +26 -0
- package/src/util/ApplicationFlagsBitField.ts +43 -0
- package/src/util/AttachmentFlagsBitField.ts +26 -0
- package/src/util/BitField.ts +178 -0
- package/src/util/ChannelFlagsBitField.ts +43 -0
- package/src/util/Channels.ts +165 -0
- package/src/util/Colors.ts +72 -0
- package/src/util/Components.ts +285 -0
- package/src/util/Constants.ts +251 -0
- package/src/util/DataResolver.ts +146 -0
- package/src/util/Enums.ts +10 -0
- package/src/util/Events.ts +178 -0
- package/src/util/GuildMemberFlagsBitField.ts +43 -0
- package/src/util/IntentsBitField.ts +35 -0
- package/src/util/InviteFlagsBitField.ts +26 -0
- package/src/util/Invites.ts +27 -0
- package/src/util/LimitedCollection.ts +73 -0
- package/src/util/MessageFlagsBitField.ts +43 -0
- package/src/util/Options.ts +215 -0
- package/src/util/Partials.ts +50 -0
- package/src/util/PermissionsBitField.ts +113 -0
- package/src/util/RoleFlagsBitField.ts +26 -0
- package/src/util/SKUFlagsBitField.ts +26 -0
- package/src/util/ShardEvents.ts +26 -0
- package/src/util/Status.ts +16 -0
- package/src/util/Sweepers.ts +532 -0
- package/src/util/Symbols.ts +1 -0
- package/src/util/SystemChannelFlagsBitField.ts +45 -0
- package/src/util/ThreadMemberFlagsBitField.ts +33 -0
- package/src/util/Transformers.ts +123 -0
- package/src/util/UserFlagsBitField.ts +33 -0
- package/src/util/Util.ts +519 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { Collection } from '@ovencord/collection';
|
|
2
|
+
import { Routes } from 'discord-api-types/v10';
|
|
3
|
+
import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
|
|
4
|
+
import { Role } from '../structures/Role.js';
|
|
5
|
+
import { DataManager } from './DataManager.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Manages API methods for roles of a GuildMember and stores their cache.
|
|
9
|
+
*
|
|
10
|
+
* @extends {DataManager}
|
|
11
|
+
*/
|
|
12
|
+
export class GuildMemberRoleManager extends DataManager {
|
|
13
|
+
public member: any;
|
|
14
|
+
public guild: any;
|
|
15
|
+
constructor(member) {
|
|
16
|
+
super(member.client, Role);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The GuildMember this manager belongs to
|
|
20
|
+
*
|
|
21
|
+
* @type {GuildMember}
|
|
22
|
+
*/
|
|
23
|
+
this.member = member;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The Guild this manager belongs to
|
|
27
|
+
*
|
|
28
|
+
* @type {Guild}
|
|
29
|
+
*/
|
|
30
|
+
this.guild = member.guild;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The roles of this member
|
|
35
|
+
*
|
|
36
|
+
* @type {Collection<Snowflake, Role>}
|
|
37
|
+
* @readonly
|
|
38
|
+
*/
|
|
39
|
+
get cache() {
|
|
40
|
+
const cache = new Collection();
|
|
41
|
+
cache.set(this.guild.id, this.guild.roles.everyone);
|
|
42
|
+
|
|
43
|
+
for (const roleId of this.member._roles) {
|
|
44
|
+
const role = this.guild.roles.cache.get(roleId);
|
|
45
|
+
if (role !== undefined) {
|
|
46
|
+
cache.set(roleId, role);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return cache;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The role of the member used to hoist them in a separate category in the users list
|
|
55
|
+
*
|
|
56
|
+
* @type {?Role}
|
|
57
|
+
* @readonly
|
|
58
|
+
*/
|
|
59
|
+
get hoist() {
|
|
60
|
+
const hoistedRoles = this.cache.filter(role => role.hoist);
|
|
61
|
+
if (!hoistedRoles.size) return null;
|
|
62
|
+
return hoistedRoles.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The role of the member used to set their role icon
|
|
67
|
+
*
|
|
68
|
+
* @type {?Role}
|
|
69
|
+
* @readonly
|
|
70
|
+
*/
|
|
71
|
+
get icon() {
|
|
72
|
+
const iconRoles = this.cache.filter(role => role.icon ?? role.unicodeEmoji);
|
|
73
|
+
if (!iconRoles.size) return null;
|
|
74
|
+
return iconRoles.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The role of the member used to set their color
|
|
79
|
+
*
|
|
80
|
+
* @type {?Role}
|
|
81
|
+
* @readonly
|
|
82
|
+
*/
|
|
83
|
+
get color() {
|
|
84
|
+
const coloredRoles = this.cache.filter(role => role.colors.primaryColor);
|
|
85
|
+
if (!coloredRoles.size) return null;
|
|
86
|
+
return coloredRoles.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The role of the member with the highest position
|
|
91
|
+
*
|
|
92
|
+
* @type {Role}
|
|
93
|
+
* @readonly
|
|
94
|
+
*/
|
|
95
|
+
get highest() {
|
|
96
|
+
return this.cache.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev), this.cache.first());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The premium subscriber role of the guild, if present on the member
|
|
101
|
+
*
|
|
102
|
+
* @type {?Role}
|
|
103
|
+
* @readonly
|
|
104
|
+
*/
|
|
105
|
+
get premiumSubscriberRole() {
|
|
106
|
+
return this.cache.find(role => role.tags?.premiumSubscriberRole) ?? null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The managed role this member created when joining the guild, if any
|
|
111
|
+
* <info>Only ever available on bots</info>
|
|
112
|
+
*
|
|
113
|
+
* @type {?Role}
|
|
114
|
+
* @readonly
|
|
115
|
+
*/
|
|
116
|
+
get botRole() {
|
|
117
|
+
if (!this.member.user.bot) return null;
|
|
118
|
+
return this.cache.find(role => role.tags?.botId === this.member.user.id) ?? null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Adds a role (or multiple roles) to the member.
|
|
123
|
+
*
|
|
124
|
+
* <info>Uses the idempotent PUT route for singular roles, otherwise PATCHes the underlying guild member</info>
|
|
125
|
+
*
|
|
126
|
+
* @param {RoleResolvable|RoleResolvable[]|Collection<Snowflake, Role>} roleOrRoles The role or roles to add
|
|
127
|
+
* @param {string} [reason] Reason for adding the role(s)
|
|
128
|
+
* @returns {Promise<GuildMember>}
|
|
129
|
+
*/
|
|
130
|
+
async add(roleOrRoles, reason) {
|
|
131
|
+
if (roleOrRoles instanceof Collection || Array.isArray(roleOrRoles)) {
|
|
132
|
+
const resolvedRoles = [];
|
|
133
|
+
for (const role of roleOrRoles.values()) {
|
|
134
|
+
const resolvedRole = this.guild.roles.resolveId(role);
|
|
135
|
+
if (!resolvedRole) {
|
|
136
|
+
throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array or Collection', 'roles', role);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
resolvedRoles.push(resolvedRole);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const newRoles = [...new Set(resolvedRoles.concat(...this.cache.keys()))];
|
|
143
|
+
return this.set(newRoles, reason);
|
|
144
|
+
} else {
|
|
145
|
+
const resolvedRoleId = this.guild.roles.resolveId(roleOrRoles);
|
|
146
|
+
if (resolvedRoleId === null) {
|
|
147
|
+
throw new DiscordjsTypeError(
|
|
148
|
+
ErrorCodes.InvalidType,
|
|
149
|
+
'roles',
|
|
150
|
+
'Role, Snowflake or Array or Collection of Roles or Snowflakes',
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
await this.client.rest.put(Routes.guildMemberRole(this.guild.id, this.member.id, resolvedRoleId), { reason });
|
|
155
|
+
|
|
156
|
+
const clone = this.member._clone();
|
|
157
|
+
clone._roles = [...this.cache.keys(), resolvedRoleId];
|
|
158
|
+
return clone;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Removes a role (or multiple roles) from the member.
|
|
164
|
+
*
|
|
165
|
+
* <info>Uses the idempotent DELETE route for singular roles, otherwise PATCHes the underlying guild member</info>
|
|
166
|
+
*
|
|
167
|
+
* @param {RoleResolvable|RoleResolvable[]|Collection<Snowflake, Role>} roleOrRoles The role or roles to remove
|
|
168
|
+
* @param {string} [reason] Reason for removing the role(s)
|
|
169
|
+
* @returns {Promise<GuildMember>}
|
|
170
|
+
*/
|
|
171
|
+
async remove(roleOrRoles, reason) {
|
|
172
|
+
if (roleOrRoles instanceof Collection || Array.isArray(roleOrRoles)) {
|
|
173
|
+
const resolvedRoles = [];
|
|
174
|
+
for (const role of roleOrRoles.values()) {
|
|
175
|
+
const resolvedRole = this.guild.roles.resolveId(role);
|
|
176
|
+
if (!resolvedRole) {
|
|
177
|
+
throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array or Collection', 'roles', role);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
resolvedRoles.push(resolvedRole);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const newRoles = this.cache.filter(role => !resolvedRoles.includes(role.id));
|
|
184
|
+
return this.set(newRoles, reason);
|
|
185
|
+
} else {
|
|
186
|
+
const resolvedRoleId = this.guild.roles.resolveId(roleOrRoles);
|
|
187
|
+
if (resolvedRoleId === null) {
|
|
188
|
+
throw new DiscordjsTypeError(
|
|
189
|
+
ErrorCodes.InvalidType,
|
|
190
|
+
'roles',
|
|
191
|
+
'Role, Snowflake or Array or Collection of Roles or Snowflakes',
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
await this.client.rest.delete(Routes.guildMemberRole(this.guild.id, this.member.id, resolvedRoleId), { reason });
|
|
196
|
+
|
|
197
|
+
const clone = this.member._clone();
|
|
198
|
+
const newRoles = this.cache.filter(role => role.id !== resolvedRoleId);
|
|
199
|
+
clone._roles = [...newRoles.keys()];
|
|
200
|
+
return clone;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Sets the roles applied to the member.
|
|
206
|
+
*
|
|
207
|
+
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles The roles or role ids to apply
|
|
208
|
+
* @param {string} [reason] Reason for applying the roles
|
|
209
|
+
* @returns {Promise<GuildMember>}
|
|
210
|
+
* @example
|
|
211
|
+
* // Set the member's roles to a single role
|
|
212
|
+
* guildMember.roles.set(['391156570408615936'])
|
|
213
|
+
* .then(console.log)
|
|
214
|
+
* .catch(console.error);
|
|
215
|
+
* @example
|
|
216
|
+
* // Remove all the roles from a member
|
|
217
|
+
* guildMember.roles.set([])
|
|
218
|
+
* .then(member => console.log(`Member roles is now of ${member.roles.cache.size} size`))
|
|
219
|
+
* .catch(console.error);
|
|
220
|
+
*/
|
|
221
|
+
async set(roles, reason) {
|
|
222
|
+
return this.member.edit({ roles, reason });
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
clone() {
|
|
226
|
+
const clone = new this.constructor(this.member);
|
|
227
|
+
clone.member._roles = [...this.cache.keys()];
|
|
228
|
+
return clone;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Routes } from 'discord-api-types/v10';
|
|
2
|
+
import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
|
|
3
|
+
import { MessageManager } from './MessageManager.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Manages API methods for messages in a guild and holds their cache.
|
|
7
|
+
*
|
|
8
|
+
* @extends {MessageManager}
|
|
9
|
+
*/
|
|
10
|
+
export class GuildMessageManager extends MessageManager {
|
|
11
|
+
/**
|
|
12
|
+
* The channel that the messages belong to
|
|
13
|
+
*
|
|
14
|
+
* @name GuildMessageManager#channel
|
|
15
|
+
* @type {GuildTextBasedChannel}
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Publishes a message in an announcement channel to all channels following it, even if it's not cached.
|
|
20
|
+
*
|
|
21
|
+
* @param {MessageResolvable} message The message to publish
|
|
22
|
+
* @returns {Promise<Message>}
|
|
23
|
+
*/
|
|
24
|
+
async crosspost(message) {
|
|
25
|
+
const messageId = this.resolveId(message);
|
|
26
|
+
if (!messageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
|
|
27
|
+
|
|
28
|
+
const data = await this.client.rest.post(Routes.channelMessageCrosspost(this.channel.id, messageId));
|
|
29
|
+
return this.cache.get(data.id) ?? this._add(data);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { Collection } from '@ovencord/collection';
|
|
2
|
+
import { makeURLSearchParams } from '@ovencord/rest';
|
|
3
|
+
import { GuildScheduledEventEntityType, Routes } from 'discord-api-types/v10';
|
|
4
|
+
import { DiscordjsTypeError, DiscordjsError, ErrorCodes } from '../errors/index.js';
|
|
5
|
+
import { GuildScheduledEvent } from '../structures/GuildScheduledEvent.js';
|
|
6
|
+
import { resolveImage } from '../util/DataResolver.js';
|
|
7
|
+
import { _transformGuildScheduledEventRecurrenceRule } from '../util/Transformers.js';
|
|
8
|
+
import { CachedManager } from './CachedManager.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Manages API methods for GuildScheduledEvents and stores their cache.
|
|
12
|
+
*
|
|
13
|
+
* @extends {CachedManager}
|
|
14
|
+
*/
|
|
15
|
+
export class GuildScheduledEventManager extends CachedManager {
|
|
16
|
+
public guild: any;
|
|
17
|
+
constructor(guild, iterable) {
|
|
18
|
+
super(guild.client, GuildScheduledEvent, iterable);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The guild this manager belongs to
|
|
22
|
+
*
|
|
23
|
+
* @type {Guild}
|
|
24
|
+
*/
|
|
25
|
+
this.guild = guild;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The cache of this manager
|
|
30
|
+
*
|
|
31
|
+
* @type {Collection<Snowflake, GuildScheduledEvent>}
|
|
32
|
+
* @name GuildScheduledEventManager#cache
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Data that resolves to give a GuildScheduledEvent object. This can be:
|
|
37
|
+
* - A Snowflake
|
|
38
|
+
* - A GuildScheduledEvent object
|
|
39
|
+
*
|
|
40
|
+
* @typedef {Snowflake|GuildScheduledEvent} GuildScheduledEventResolvable
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Options for setting a recurrence rule for a guild scheduled event.
|
|
45
|
+
*
|
|
46
|
+
* @typedef {Object} GuildScheduledEventRecurrenceRuleOptions
|
|
47
|
+
* @property {DateResolvable} startAt The time the recurrence rule interval starts at
|
|
48
|
+
* @property {GuildScheduledEventRecurrenceRuleFrequency} frequency How often the event occurs
|
|
49
|
+
* @property {number} interval The spacing between the events
|
|
50
|
+
* @property {?GuildScheduledEventRecurrenceRuleWeekday[]} byWeekday The days within a week to recur on
|
|
51
|
+
* @property {?GuildScheduledEventRecurrenceRuleNWeekday[]} byNWeekday The days within a week to recur on
|
|
52
|
+
* @property {?GuildScheduledEventRecurrenceRuleMonth[]} byMonth The months to recur on
|
|
53
|
+
* @property {?number[]} byMonthDay The days within a month to recur on
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Options used to create a guild scheduled event.
|
|
58
|
+
*
|
|
59
|
+
* @typedef {Object} GuildScheduledEventCreateOptions
|
|
60
|
+
* @property {string} name The name of the guild scheduled event
|
|
61
|
+
* @property {DateResolvable} scheduledStartTime The time to schedule the event at
|
|
62
|
+
* @property {DateResolvable} [scheduledEndTime] The time to end the event at
|
|
63
|
+
* <warn>This is required if `entityType` is {@link GuildScheduledEventEntityType.External}</warn>
|
|
64
|
+
* @property {GuildScheduledEventPrivacyLevel} privacyLevel The privacy level of the guild scheduled event
|
|
65
|
+
* @property {GuildScheduledEventEntityType} entityType The scheduled entity type of the event
|
|
66
|
+
* @property {string} [description] The description of the guild scheduled event
|
|
67
|
+
* @property {GuildVoiceChannelResolvable} [channel] The channel of the guild scheduled event
|
|
68
|
+
* <warn>This is required if `entityType` is {@link GuildScheduledEventEntityType.StageInstance} or
|
|
69
|
+
* {@link GuildScheduledEventEntityType.Voice}</warn>
|
|
70
|
+
* @property {GuildScheduledEventEntityMetadataOptions} [entityMetadata] The entity metadata of the
|
|
71
|
+
* guild scheduled event
|
|
72
|
+
* <warn>This is required if `entityType` is {@link GuildScheduledEventEntityType.External}</warn>
|
|
73
|
+
* @property {?(BufferResolvable|Base64Resolvable)} [image] The cover image of the guild scheduled event
|
|
74
|
+
* @property {string} [reason] The reason for creating the guild scheduled event
|
|
75
|
+
* @property {GuildScheduledEventRecurrenceRuleOptions} [recurrenceRule]
|
|
76
|
+
* The recurrence rule of the guild scheduled event
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Options used to set entity metadata of a guild scheduled event.
|
|
81
|
+
*
|
|
82
|
+
* @typedef {Object} GuildScheduledEventEntityMetadataOptions
|
|
83
|
+
* @property {string} [location] The location of the guild scheduled event
|
|
84
|
+
* <warn>This is required if `entityType` is {@link GuildScheduledEventEntityType.External}</warn>
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new guild scheduled event.
|
|
89
|
+
*
|
|
90
|
+
* @param {GuildScheduledEventCreateOptions} options Options for creating the guild scheduled event
|
|
91
|
+
* @returns {Promise<GuildScheduledEvent>}
|
|
92
|
+
*/
|
|
93
|
+
async create(options) {
|
|
94
|
+
if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
|
|
95
|
+
const {
|
|
96
|
+
privacyLevel,
|
|
97
|
+
entityType,
|
|
98
|
+
channel,
|
|
99
|
+
name,
|
|
100
|
+
scheduledStartTime,
|
|
101
|
+
description,
|
|
102
|
+
scheduledEndTime,
|
|
103
|
+
entityMetadata,
|
|
104
|
+
reason,
|
|
105
|
+
image,
|
|
106
|
+
recurrenceRule,
|
|
107
|
+
} = options;
|
|
108
|
+
|
|
109
|
+
let channel_id;
|
|
110
|
+
let entity_metadata;
|
|
111
|
+
if (entityType === GuildScheduledEventEntityType.External) {
|
|
112
|
+
channel_id = channel === undefined ? channel : null;
|
|
113
|
+
entity_metadata = { location: entityMetadata?.location };
|
|
114
|
+
} else {
|
|
115
|
+
channel_id = this.guild.channels.resolveId(channel);
|
|
116
|
+
if (!channel_id) throw new DiscordjsError(ErrorCodes.GuildVoiceChannelResolve);
|
|
117
|
+
entity_metadata = entityMetadata === undefined ? entityMetadata : null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const data = await this.client.rest.post(Routes.guildScheduledEvents(this.guild.id), {
|
|
121
|
+
body: {
|
|
122
|
+
channel_id,
|
|
123
|
+
name,
|
|
124
|
+
privacy_level: privacyLevel,
|
|
125
|
+
scheduled_start_time: new Date(scheduledStartTime).toISOString(),
|
|
126
|
+
scheduled_end_time: scheduledEndTime ? new Date(scheduledEndTime).toISOString() : scheduledEndTime,
|
|
127
|
+
description,
|
|
128
|
+
entity_type: entityType,
|
|
129
|
+
entity_metadata,
|
|
130
|
+
image: image && (await resolveImage(image)),
|
|
131
|
+
recurrence_rule: recurrenceRule && _transformGuildScheduledEventRecurrenceRule(recurrenceRule),
|
|
132
|
+
},
|
|
133
|
+
reason,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return this._add(data);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Options used to fetch a single guild scheduled event from a guild.
|
|
141
|
+
*
|
|
142
|
+
* @typedef {BaseFetchOptions} FetchGuildScheduledEventOptions
|
|
143
|
+
* @property {GuildScheduledEventResolvable} guildScheduledEvent The guild scheduled event to fetch
|
|
144
|
+
* @property {boolean} [withUserCount=true] Whether to fetch the number of users subscribed to the scheduled event
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Options used to fetch multiple guild scheduled events from a guild.
|
|
149
|
+
*
|
|
150
|
+
* @typedef {Object} FetchGuildScheduledEventsOptions
|
|
151
|
+
* @property {boolean} [cache] Whether or not to cache the fetched guild scheduled events
|
|
152
|
+
* @property {boolean} [withUserCount=true] Whether to fetch the number of users subscribed to each scheduled event
|
|
153
|
+
* should be returned
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Obtains one or more guild scheduled events from Discord, or the guild cache if it's already available.
|
|
158
|
+
*
|
|
159
|
+
* @param {GuildScheduledEventResolvable|FetchGuildScheduledEventOptions|FetchGuildScheduledEventsOptions} [options]
|
|
160
|
+
* The id of the guild scheduled event or options
|
|
161
|
+
* @returns {Promise<GuildScheduledEvent|Collection<Snowflake, GuildScheduledEvent>>}
|
|
162
|
+
*/
|
|
163
|
+
async fetch(options = {}) {
|
|
164
|
+
const id = this.resolveId(options.guildScheduledEvent ?? options);
|
|
165
|
+
|
|
166
|
+
if (id) {
|
|
167
|
+
if (!options.force) {
|
|
168
|
+
const existing = this.cache.get(id);
|
|
169
|
+
if (existing) return existing;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const innerData = await this.client.rest.get(Routes.guildScheduledEvent(this.guild.id, id), {
|
|
173
|
+
query: makeURLSearchParams({ with_user_count: options.withUserCount ?? true }),
|
|
174
|
+
});
|
|
175
|
+
return this._add(innerData, options.cache);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const data = await this.client.rest.get(Routes.guildScheduledEvents(this.guild.id), {
|
|
179
|
+
query: makeURLSearchParams({ with_user_count: options.withUserCount ?? true }),
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
return data.reduce(
|
|
183
|
+
(coll, rawGuildScheduledEventData) =>
|
|
184
|
+
coll.set(rawGuildScheduledEventData.id, this._add(rawGuildScheduledEventData, options.cache)),
|
|
185
|
+
new Collection(),
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Options used to edit a guild scheduled event.
|
|
191
|
+
*
|
|
192
|
+
* @typedef {Object} GuildScheduledEventEditOptions
|
|
193
|
+
* @property {string} [name] The name of the guild scheduled event
|
|
194
|
+
* @property {DateResolvable} [scheduledStartTime] The time to schedule the event at
|
|
195
|
+
* @property {DateResolvable} [scheduledEndTime] The time to end the event at
|
|
196
|
+
* @property {GuildScheduledEventPrivacyLevel} [privacyLevel] The privacy level of the guild scheduled event
|
|
197
|
+
* @property {GuildScheduledEventEntityType} [entityType] The scheduled entity type of the event
|
|
198
|
+
* @property {string} [description] The description of the guild scheduled event
|
|
199
|
+
* @property {?GuildVoiceChannelResolvable} [channel] The channel of the guild scheduled event
|
|
200
|
+
* @property {GuildScheduledEventStatus} [status] The status of the guild scheduled event
|
|
201
|
+
* @property {GuildScheduledEventEntityMetadataOptions} [entityMetadata] The entity metadata of the
|
|
202
|
+
* guild scheduled event
|
|
203
|
+
* <warn>This can be modified only if `entityType` of the `GuildScheduledEvent` to be edited is
|
|
204
|
+
* {@link GuildScheduledEventEntityType.External}</warn>
|
|
205
|
+
* @property {?(BufferResolvable|Base64Resolvable)} [image] The cover image of the guild scheduled event
|
|
206
|
+
* @property {string} [reason] The reason for editing the guild scheduled event
|
|
207
|
+
* @property {?GuildScheduledEventRecurrenceRuleOptions} [recurrenceRule]
|
|
208
|
+
* The recurrence rule of the guild scheduled event
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Edits a guild scheduled event.
|
|
213
|
+
*
|
|
214
|
+
* @param {GuildScheduledEventResolvable} guildScheduledEvent The guild scheduled event to edit
|
|
215
|
+
* @param {GuildScheduledEventEditOptions} options Options to edit the guild scheduled event
|
|
216
|
+
* @returns {Promise<GuildScheduledEvent>}
|
|
217
|
+
*/
|
|
218
|
+
async edit(guildScheduledEvent, options) {
|
|
219
|
+
const guildScheduledEventId = this.resolveId(guildScheduledEvent);
|
|
220
|
+
if (!guildScheduledEventId) throw new DiscordjsError(ErrorCodes.GuildScheduledEventResolve);
|
|
221
|
+
|
|
222
|
+
if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
|
|
223
|
+
const {
|
|
224
|
+
privacyLevel,
|
|
225
|
+
entityType,
|
|
226
|
+
channel,
|
|
227
|
+
status,
|
|
228
|
+
name,
|
|
229
|
+
scheduledStartTime,
|
|
230
|
+
description,
|
|
231
|
+
scheduledEndTime,
|
|
232
|
+
entityMetadata,
|
|
233
|
+
reason,
|
|
234
|
+
image,
|
|
235
|
+
recurrenceRule,
|
|
236
|
+
} = options;
|
|
237
|
+
|
|
238
|
+
let entity_metadata;
|
|
239
|
+
if (entityMetadata) {
|
|
240
|
+
entity_metadata = {
|
|
241
|
+
location: entityMetadata.location,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const data = await this.client.rest.patch(Routes.guildScheduledEvent(this.guild.id, guildScheduledEventId), {
|
|
246
|
+
body: {
|
|
247
|
+
channel_id: channel === undefined ? channel : this.guild.channels.resolveId(channel),
|
|
248
|
+
name,
|
|
249
|
+
privacy_level: privacyLevel,
|
|
250
|
+
scheduled_start_time: scheduledStartTime ? new Date(scheduledStartTime).toISOString() : undefined,
|
|
251
|
+
scheduled_end_time: scheduledEndTime ? new Date(scheduledEndTime).toISOString() : scheduledEndTime,
|
|
252
|
+
description,
|
|
253
|
+
entity_type: entityType,
|
|
254
|
+
status,
|
|
255
|
+
image: image && (await resolveImage(image)),
|
|
256
|
+
entity_metadata,
|
|
257
|
+
recurrence_rule: recurrenceRule && _transformGuildScheduledEventRecurrenceRule(recurrenceRule),
|
|
258
|
+
},
|
|
259
|
+
reason,
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
return this._add(data);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Deletes a guild scheduled event.
|
|
267
|
+
*
|
|
268
|
+
* @param {GuildScheduledEventResolvable} guildScheduledEvent The guild scheduled event to delete
|
|
269
|
+
* @returns {Promise<void>}
|
|
270
|
+
*/
|
|
271
|
+
async delete(guildScheduledEvent) {
|
|
272
|
+
const guildScheduledEventId = this.resolveId(guildScheduledEvent);
|
|
273
|
+
if (!guildScheduledEventId) throw new DiscordjsError(ErrorCodes.GuildScheduledEventResolve);
|
|
274
|
+
|
|
275
|
+
await this.client.rest.delete(Routes.guildScheduledEvent(this.guild.id, guildScheduledEventId));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Options used to fetch subscribers of a guild scheduled event
|
|
280
|
+
*
|
|
281
|
+
* @typedef {Object} FetchGuildScheduledEventSubscribersOptions
|
|
282
|
+
* @property {number} [limit] The maximum numbers of users to fetch
|
|
283
|
+
* @property {boolean} [withMember] Whether to fetch guild member data of the users
|
|
284
|
+
* @property {Snowflake} [before] Consider only users before this user id
|
|
285
|
+
* @property {Snowflake} [after] Consider only users after this user id
|
|
286
|
+
* <warn>If both `before` and `after` are provided, only `before` is respected</warn>
|
|
287
|
+
*/
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Represents a subscriber of a {@link GuildScheduledEvent}
|
|
291
|
+
*
|
|
292
|
+
* @typedef {Object} GuildScheduledEventUser
|
|
293
|
+
* @property {Snowflake} guildScheduledEventId The id of the guild scheduled event which the user subscribed to
|
|
294
|
+
* @property {User} user The user that subscribed to the guild scheduled event
|
|
295
|
+
* @property {?GuildMember} member The guild member associated with the user, if any
|
|
296
|
+
*/
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Fetches subscribers of a guild scheduled event.
|
|
300
|
+
*
|
|
301
|
+
* @param {GuildScheduledEventResolvable} guildScheduledEvent The guild scheduled event to fetch subscribers of
|
|
302
|
+
* @param {FetchGuildScheduledEventSubscribersOptions} [options={}] Options for fetching the subscribers
|
|
303
|
+
* @returns {Promise<Collection<Snowflake, GuildScheduledEventUser>>}
|
|
304
|
+
*/
|
|
305
|
+
async fetchSubscribers(guildScheduledEvent, options = {}) {
|
|
306
|
+
const guildScheduledEventId = this.resolveId(guildScheduledEvent);
|
|
307
|
+
if (!guildScheduledEventId) throw new DiscordjsError(ErrorCodes.GuildScheduledEventResolve);
|
|
308
|
+
|
|
309
|
+
const query = makeURLSearchParams({
|
|
310
|
+
limit: options.limit,
|
|
311
|
+
with_member: options.withMember,
|
|
312
|
+
before: options.before,
|
|
313
|
+
after: options.after,
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const data = await this.client.rest.get(Routes.guildScheduledEventUsers(this.guild.id, guildScheduledEventId), {
|
|
317
|
+
query,
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
return data.reduce(
|
|
321
|
+
(coll, rawData) =>
|
|
322
|
+
coll.set(rawData.user.id, {
|
|
323
|
+
guildScheduledEventId: rawData.guild_scheduled_event_id,
|
|
324
|
+
user: this.client.users._add(rawData.user),
|
|
325
|
+
member: rawData.member ? this.guild.members._add({ ...rawData.member, user: rawData.user }) : null,
|
|
326
|
+
}),
|
|
327
|
+
new Collection(),
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
}
|