mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor: Strengthen channel typings in appropriate places (#6232)
This commit is contained in:
@@ -86,7 +86,7 @@ class GuildChannelManager extends CachedManager {
|
||||
* @property {boolean} [nsfw] Whether the new channel is nsfw
|
||||
* @property {number} [bitrate] Bitrate of the new channel in bits (only voice)
|
||||
* @property {number} [userLimit] Maximum amount of users allowed in the new channel (only voice)
|
||||
* @property {ChannelResolvable} [parent] Parent of the new channel
|
||||
* @property {CategoryChannelResolvable} [parent] Parent of the new channel
|
||||
* @property {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [permissionOverwrites]
|
||||
* Permission overwrites of the new channel
|
||||
* @property {number} [position] Position of the new channel
|
||||
|
||||
@@ -22,7 +22,7 @@ class CategoryChannel extends GuildChannel {
|
||||
* @method setParent
|
||||
* @memberof CategoryChannel
|
||||
* @instance
|
||||
* @param {?(GuildChannel|Snowflake)} channel The channel to set as parent
|
||||
* @param {?CategoryChannelResolvable} channel The channel to set as parent
|
||||
* @param {SetParentOptions} [options={}] The options for setting the parent
|
||||
* @returns {Promise<GuildChannel>}
|
||||
*/
|
||||
|
||||
@@ -776,8 +776,8 @@ class Guild extends AnonymousGuild {
|
||||
* @property {string} [name] The name of the guild
|
||||
* @property {VerificationLevel|number} [verificationLevel] The verification level of the guild
|
||||
* @property {ExplicitContentFilterLevel|number} [explicitContentFilter] The level of the explicit content filter
|
||||
* @property {ChannelResolvable} [afkChannel] The AFK channel of the guild
|
||||
* @property {ChannelResolvable} [systemChannel] The system channel of the guild
|
||||
* @property {VoiceChannelResolvable} [afkChannel] The AFK channel of the guild
|
||||
* @property {TextChannelResolvable} [systemChannel] The system channel of the guild
|
||||
* @property {number} [afkTimeout] The AFK timeout of the guild
|
||||
* @property {Base64Resolvable} [icon] The icon of the guild
|
||||
* @property {GuildMemberResolvable} [owner] The owner of the guild
|
||||
@@ -787,13 +787,27 @@ class Guild extends AnonymousGuild {
|
||||
* @property {DefaultMessageNotificationLevel|number} [defaultMessageNotifications] The default message notification
|
||||
* level of the guild
|
||||
* @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild
|
||||
* @property {ChannelResolvable} [rulesChannel] The rules channel of the guild
|
||||
* @property {ChannelResolvable} [publicUpdatesChannel] The community updates channel of the guild
|
||||
* @property {TextChannelResolvable} [rulesChannel] The rules channel of the guild
|
||||
* @property {TextChannelResolvable} [publicUpdatesChannel] The community updates channel of the guild
|
||||
* @property {string} [preferredLocale] The preferred locale of the guild
|
||||
* @property {string} [description] The discovery description of the guild
|
||||
* @property {Features[]} [features] The features of the guild
|
||||
*/
|
||||
|
||||
/**
|
||||
* Data that can be resolved to a Text Channel object. This can be:
|
||||
* * A TextChannel
|
||||
* * A Snowflake
|
||||
* @typedef {TextChannel|Snowflake} TextChannelResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Data that can be resolved to a Voice Channel object. This can be:
|
||||
* * A VoiceChannel
|
||||
* * A Snowflake
|
||||
* @typedef {VoiceChannel|Snowflake} VoiceChannelResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Updates the guild with new information - e.g. a new name.
|
||||
* @param {GuildEditData} data The data to update the guild with
|
||||
@@ -886,6 +900,14 @@ class Guild extends AnonymousGuild {
|
||||
* @typedef {TextChannel|NewsChannel|Snowflake} GuildTextChannelResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Data that can be resolved to a GuildVoiceChannel object. This can be:
|
||||
* * A VoiceChannel
|
||||
* * A StageChannel
|
||||
* * A Snowflake
|
||||
* @typedef {VoiceChannel|StageChannel|Snowflake} GuildVoiceChannelResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Updates the guild's welcome screen
|
||||
* @param {WelcomeScreenEditData} data Data to edit the welcome screen with
|
||||
@@ -988,7 +1010,7 @@ class Guild extends AnonymousGuild {
|
||||
|
||||
/**
|
||||
* Edits the AFK channel of the guild.
|
||||
* @param {ChannelResolvable} afkChannel The new AFK channel
|
||||
* @param {VoiceChannelResolvable} afkChannel The new AFK channel
|
||||
* @param {string} [reason] Reason for changing the guild's AFK channel
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
@@ -1003,7 +1025,7 @@ class Guild extends AnonymousGuild {
|
||||
|
||||
/**
|
||||
* Edits the system channel of the guild.
|
||||
* @param {ChannelResolvable} systemChannel The new system channel
|
||||
* @param {TextChannelResolvable} systemChannel The new system channel
|
||||
* @param {string} [reason] Reason for changing the guild's system channel
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
@@ -1107,7 +1129,7 @@ class Guild extends AnonymousGuild {
|
||||
|
||||
/**
|
||||
* Edits the rules channel of the guild.
|
||||
* @param {ChannelResolvable} rulesChannel The new rules channel
|
||||
* @param {TextChannelResolvable} rulesChannel The new rules channel
|
||||
* @param {string} [reason] Reason for changing the guild's rules channel
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
@@ -1122,7 +1144,7 @@ class Guild extends AnonymousGuild {
|
||||
|
||||
/**
|
||||
* Edits the community updates channel of the guild.
|
||||
* @param {ChannelResolvable} publicUpdatesChannel The new community updates channel
|
||||
* @param {TextChannelResolvable} publicUpdatesChannel The new community updates channel
|
||||
* @param {string} [reason] Reason for changing the guild's community updates channel
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
@@ -1160,7 +1182,7 @@ class Guild extends AnonymousGuild {
|
||||
/**
|
||||
* The data needed for updating a channel's position.
|
||||
* @typedef {Object} ChannelPosition
|
||||
* @property {ChannelResolvable} channel Channel to update
|
||||
* @property {GuildChannel|Snowflake} channel Channel to update
|
||||
* @property {number} [position] New position for the channel
|
||||
* @property {CategoryChannelResolvable} [parent] Parent channel for this channel
|
||||
* @property {boolean} [lockPermissions] If the overwrites should be locked to the parents overwrites
|
||||
|
||||
@@ -277,7 +277,7 @@ class GuildChannel extends Channel {
|
||||
* @property {boolean} [nsfw] Whether the channel is NSFW
|
||||
* @property {number} [bitrate] The bitrate of the voice channel
|
||||
* @property {number} [userLimit] The user limit of the voice channel
|
||||
* @property {?Snowflake} [parentId] The parent's id of the channel
|
||||
* @property {?CategoryChannelResolvable} [parent] The parent of the channel
|
||||
* @property {boolean} [lockPermissions]
|
||||
* Lock the permissions of the channel to what the parent's permissions are
|
||||
* @property {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [permissionOverwrites]
|
||||
@@ -300,6 +300,8 @@ class GuildChannel extends Channel {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async edit(data, reason) {
|
||||
if (data.parent) data.parent = this.client.channels.resolveId(data.parent);
|
||||
|
||||
if (typeof data.position !== 'undefined') {
|
||||
await Util.setPosition(
|
||||
this,
|
||||
@@ -323,8 +325,8 @@ class GuildChannel extends Channel {
|
||||
}
|
||||
|
||||
if (data.lockPermissions) {
|
||||
if (data.parentId) {
|
||||
const newParent = this.guild.channels.resolve(data.parentId);
|
||||
if (data.parent) {
|
||||
const newParent = this.guild.channels.resolve(data.parent);
|
||||
if (newParent?.type === 'GUILD_CATEGORY') {
|
||||
permission_overwrites = newParent.permissionOverwrites.cache.map(o =>
|
||||
PermissionOverwrites.resolve(o, this.guild),
|
||||
@@ -346,7 +348,7 @@ class GuildChannel extends Channel {
|
||||
bitrate: data.bitrate ?? this.bitrate,
|
||||
user_limit: data.userLimit ?? this.userLimit,
|
||||
rtc_region: data.rtcRegion ?? this.rtcRegion,
|
||||
parent_id: data.parentId,
|
||||
parent_id: data.parent,
|
||||
lock_permissions: data.lockPermissions,
|
||||
rate_limit_per_user: data.rateLimitPerUser,
|
||||
default_auto_archive_duration: data.defaultAutoArchiveDuration,
|
||||
@@ -382,7 +384,7 @@ class GuildChannel extends Channel {
|
||||
|
||||
/**
|
||||
* Sets the parent of this channel.
|
||||
* @param {?(CategoryChannel|Snowflake)} channel The category channel to set as parent
|
||||
* @param {?CategoryChannelResolvable} channel The category channel to set as the parent
|
||||
* @param {SetParentOptions} [options={}] The options for setting the parent
|
||||
* @returns {Promise<GuildChannel>}
|
||||
* @example
|
||||
@@ -395,7 +397,7 @@ class GuildChannel extends Channel {
|
||||
return this.edit(
|
||||
{
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
parentId: channel?.id ?? channel ?? null,
|
||||
parent: channel ?? null,
|
||||
lockPermissions,
|
||||
},
|
||||
reason,
|
||||
|
||||
@@ -236,8 +236,8 @@ class GuildMember extends Base {
|
||||
* @property {Collection<Snowflake, Role>|RoleResolvable[]} [roles] The roles or role ids to apply
|
||||
* @property {boolean} [mute] Whether or not the member should be muted
|
||||
* @property {boolean} [deaf] Whether or not the member should be deafened
|
||||
* @property {ChannelResolvable|null} [channel] Channel to move member to (if they are connected to voice), or `null`
|
||||
* if you want to kick them from voice
|
||||
* @property {GuildVoiceChannelResolvable|null} [channel] Channel to move member to (if they are connected to voice),
|
||||
* or `null` if you want to disconnect them from voice
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -203,7 +203,7 @@ class Role extends Base {
|
||||
/**
|
||||
* Returns `channel.permissionsFor(role)`. Returns permissions for a role in a guild channel,
|
||||
* taking into account permission overwrites.
|
||||
* @param {ChannelResolvable} channel The guild channel to use as context
|
||||
* @param {GuildChannel|Snowflake} channel The guild channel to use as context
|
||||
* @returns {Readonly<Permissions>}
|
||||
*/
|
||||
permissionsIn(channel) {
|
||||
|
||||
@@ -149,8 +149,8 @@ class VoiceState extends Base {
|
||||
|
||||
/**
|
||||
* Moves the member to a different channel, or disconnects them from the one they're in.
|
||||
* @param {ChannelResolvable|null} channel Channel to move the member to, or `null` if you want to disconnect them
|
||||
* from voice.
|
||||
* @param {VoiceChannelResolvable|null} channel Channel to move the member to, or `null` if you want to disconnect
|
||||
* them from voice.
|
||||
* @param {string} [reason] Reason for moving member to another channel or disconnecting
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const Channel = require('./Channel');
|
||||
const MessagePayload = require('./MessagePayload');
|
||||
const { Error } = require('../errors');
|
||||
const { WebhookTypes } = require('../util/Constants');
|
||||
@@ -214,7 +213,7 @@ class Webhook {
|
||||
* @typedef {Object} WebhookEditData
|
||||
* @property {string} [name=this.name] The new name for the webhook
|
||||
* @property {BufferResolvable} [avatar] The new avatar for the webhook
|
||||
* @property {ChannelResolvable} [channel] The new channel for the webhook
|
||||
* @property {GuildTextChannelResolvable} [channel] The new channel for the webhook
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -227,7 +226,7 @@ class Webhook {
|
||||
if (avatar && !(typeof avatar === 'string' && avatar.startsWith('data:'))) {
|
||||
avatar = await DataResolver.resolveImage(avatar);
|
||||
}
|
||||
if (channel) channel = channel instanceof Channel ? channel.id : channel;
|
||||
if (channel) channel = channel?.id ?? channel;
|
||||
const data = await this.client.api.webhooks(this.id, channel ? undefined : this.token).patch({
|
||||
data: { name, avatar, channel_id: channel },
|
||||
reason,
|
||||
|
||||
Reference in New Issue
Block a user