fix: Miscellaneous fixes

#9445 djs
This commit is contained in:
Elysia 2023-05-02 11:34:13 +07:00
parent fbaf7ed7c8
commit f4dbc57f42
16 changed files with 45 additions and 27 deletions

File diff suppressed because one or more lines are too long

View File

@ -1147,5 +1147,5 @@ module.exports = Client;
/**
* @external Collection
* @see {@link https://discord.js.org/#/docs/collection/main/class/Collection}
* @see {@link https://discord.js.org/docs/packages/collection/stable/Collection:Class}
*/

View File

@ -258,10 +258,10 @@ module.exports = ApplicationCommandManager;
/**
* @external SlashCommandBuilder
* @see {@link https://discord.js.org/#/docs/builders/main/class/SlashCommandBuilder}
* @see {@link https://discord.js.org/docs/packages/builders/stable/SlashCommandBuilder:Class}
*/
/**
* @external ContextMenuCommandBuilder
* @see {@link https://discord.js.org/#/docs/builders/main/class/ContextMenuCommandBuilder}
* @see {@link https://discord.js.org/docs/packages/builders/stable/ContextMenuCommandBuilder:Class}
*/

View File

@ -33,10 +33,10 @@ class ChannelManager extends CachedManager {
* @name ChannelManager#cache
*/
_add(data, guild, { cache = true, allowUnknownGuild = false, fromInteraction = false } = {}) {
_add(data, guild, { cache = true, allowUnknownGuild = false } = {}) {
const existing = this.cache.get(data.id);
if (existing) {
if (cache) existing._patch(data, fromInteraction);
if (cache) existing._patch(data);
guild?.channels?._add(existing);
if (ThreadChannelTypes.includes(existing.type)) {
existing.parent?.threads?._add(existing);
@ -44,7 +44,7 @@ class ChannelManager extends CachedManager {
return existing;
}
const channel = Channel.create(this.client, data, guild, { allowUnknownGuild, fromInteraction });
const channel = Channel.create(this.client, data, guild, { allowUnknownGuild });
if (!channel) {
this.client.emit(Events.DEBUG, `Failed to find guild, or unknown type for channel ${data.id} ${data.type}`);

View File

@ -299,11 +299,14 @@ class RoleManager extends CachedManager {
const resolvedRole2 = this.resolve(role2);
if (!resolvedRole1 || !resolvedRole2) throw new TypeError('INVALID_TYPE', 'role', 'Role nor a Snowflake');
if (resolvedRole1.position === resolvedRole2.position) {
const role1Position = resolvedRole1.position;
const role2Position = resolvedRole2.position;
if (role1Position === role2Position) {
return Number(BigInt(resolvedRole2.id) - BigInt(resolvedRole1.id));
}
return resolvedRole1.position - resolvedRole2.position;
return role1Position - role2Position;
}
/**

View File

@ -7,6 +7,19 @@ const GuildChannel = require('./GuildChannel');
* @extends {GuildChannel}
*/
class CategoryChannel extends GuildChannel {
/**
* The id of the parent of this channel.
* @name CategoryChannel#parentId
* @type {null}
*/
/**
* The parent of this channel.
* @name CategoryChannel#parent
* @type {null}
* @readonly
*/
/**
* Channels that are a part of this category
* @type {Collection<Snowflake, GuildChannel>}
@ -18,7 +31,7 @@ class CategoryChannel extends GuildChannel {
/**
* Sets the category parent of this channel.
* <warn>It is not currently possible to set the parent of a CategoryChannel.</warn>
* <warn>It is not possible to set the parent of a CategoryChannel.</warn>
* @method setParent
* @memberof CategoryChannel
* @instance

View File

@ -186,7 +186,7 @@ class Channel extends Base {
return this.type === 'GUILD_DIRECTORY';
}
static create(client, data, guild, { allowUnknownGuild, fromInteraction } = {}) {
static create(client, data, guild, { allowUnknownGuild } = {}) {
CategoryChannel ??= require('./CategoryChannel');
DMChannel ??= require('./DMChannel');
NewsChannel ??= require('./NewsChannel');
@ -238,7 +238,7 @@ class Channel extends Base {
case ChannelTypes.GUILD_NEWS_THREAD:
case ChannelTypes.GUILD_PUBLIC_THREAD:
case ChannelTypes.GUILD_PRIVATE_THREAD: {
channel = new ThreadChannel(guild, data, client, fromInteraction);
channel = new ThreadChannel(guild, data, client);
if (!allowUnknownGuild) channel.parent?.threads.cache.set(channel.id, channel);
break;
}

View File

@ -722,7 +722,7 @@ class Message extends Base {
* @property {MessageAttachment[]} [attachments] An array of attachments to keep,
* all attachments will be kept if omitted
* @property {FileOptions[]|BufferResolvable[]|MessageAttachment[]} [files] Files to add to the message
* @property {MessageActionRow[]|MessageActionRowOptions[]} [components]
* @property {Array<(MessageActionRow|MessageActionRowOptions)>} [components]
* Action rows containing interactive components for the message (buttons, select menus)
*/

View File

@ -14,7 +14,7 @@ class Modal {
* @typedef {Object} ModalOptions
* @property {string} [customId] A unique string to be sent in the interaction when clicked
* @property {string} [title] The title to be displayed on this modal
* @property {MessageActionRow[]|MessageActionRowOptions[]} [components]
* @property {Array<(MessageActionRow|MessageActionRowOptions)>} [components]
* Action rows containing interactive components for the modal (text input components)
*/

View File

@ -16,7 +16,7 @@ const { resolveAutoArchiveMaxLimit } = require('../util/Util');
* @implements {TextBasedChannel}
*/
class ThreadChannel extends Channel {
constructor(guild, data, client, fromInteraction = false) {
constructor(guild, data, client) {
super(guild?.client ?? client, data, false);
/**
@ -48,7 +48,7 @@ class ThreadChannel extends Channel {
* @type {InteractionManager}
*/
this.interactions = new InteractionManager(this);
if (data) this._patch(data, fromInteraction);
if (data) this._patch(data);
}
/**

View File

@ -127,7 +127,7 @@ class Webhook {
* @property {FileOptions[]|BufferResolvable[]|MessageAttachment[]} [files] See {@link BaseMessageOptions#files}
* @property {MessageMentionOptions} [allowedMentions] See {@link BaseMessageOptions#allowedMentions}
* @property {MessageAttachment[]} [attachments] Attachments to send with the message
* @property {MessageActionRow[]|MessageActionRowOptions[]} [components]
* @property {Array<(MessageActionRow|MessageActionRowOptions)>} [components]
* Action rows containing interactive components for the message (buttons, select menus)
* @property {Snowflake} [threadId] The id of the thread this message belongs to
* <info>For interaction webhooks, this property is ignored</info>

View File

@ -76,12 +76,12 @@ class TextBasedChannel {
* @property {boolean} [tts=false] Whether or not the message should be spoken aloud
* @property {string} [nonce=''] The nonce for the message
* @property {string} [content=''] The content for the message
* @property {WebEmbed[]|MessageEmbed[]|APIEmbed[]} [embeds] The embeds for the message
* @property {Array<(MessageEmbed|APIEmbed|WebEmbed)>} [embeds] The embeds for the message
* (see [here](https://discord.com/developers/docs/resources/channel#embed-object) for more details)
* @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content
* (see [here](https://discord.com/developers/docs/resources/channel#allowed-mentions-object) for more details)
* @property {FileOptions[]|BufferResolvable[]|MessageAttachment[]} [files] Files to send with the message
* @property {MessageActionRow[]|MessageActionRowOptions[]} [components]
* @property {Array<(FileOptions|BufferResolvable|MessageAttachment[])>} [files] Files to send with the message
* @property {Array<(MessageActionRow|MessageActionRowOptions)>} [components]
* Action rows containing interactive components for the message (buttons, select menus)
* @property {MessageAttachment[]} [attachments] Attachments to send in the message
* @property {boolean} [usingNewAttachmentAPI] Whether to use the new attachment API (`channels/:id/attachments`)

View File

@ -10,7 +10,7 @@ const { TypeError } = require('../errors/DJSError.js');
* @typedef {Function} SweepFilter
* @param {LimitedCollection} collection The collection being swept
* @returns {Function|null} Return `null` to skip sweeping, otherwise a function passed to `sweep()`,
* See {@link [Collection#sweep](https://discord.js.org/#/docs/collection/main/class/Collection?scrollTo=sweep)}
* See {@link [Collection#sweep](https://discord.js.org/docs/packages/collection/stable/Collection:Class?scrollTo=sweep)}
* for the definition of this function.
*/

View File

@ -308,7 +308,7 @@ class Options extends null {
}
/**
* The default settings passed to {@link Options.cacheWithLimits}.
* The default settings passed to {@link ClientOptions.makeCache}.
* The caches that this changes are:
* * `MessageManager` - Limit to 200 messages
* * `ChannelManager` - Sweep archived threads
@ -340,11 +340,11 @@ class Options extends null {
}
/**
* The default settings passed to {@link Options.sweepers} (for v14).
* The default settings passed to {@link ClientOptions.sweepers}.
* The sweepers that this changes are:
* * `threads` - Sweep archived threads every hour, removing those archived more than 4 hours ago
* <info>If you want to keep default behavior and add on top of it you can use this object and add on to it, e.g.
* `sweepers: { ...Options.defaultSweeperSettings, messages: { interval: 300, lifetime: 600 } })`</info>
* `sweepers: { ...Options.defaultSweeperSettings, messages: { interval: 300, lifetime: 600 } }`</info>
* @type {SweeperOptions}
*/
Options.defaultSweeperSettings = {

View File

@ -7,7 +7,7 @@ const { TypeError } = require('../errors/DJSError.js');
/**
* @typedef {Function} GlobalSweepFilter
* @returns {Function|null} Return `null` to skip sweeping, otherwise a function passed to `sweep()`,
* See {@link [Collection#sweep](https://discord.js.org/#/docs/collection/main/class/Collection?scrollTo=sweep)}
* See {@link [Collection#sweep](https://discord.js.org/docs/packages/collection/stable/Collection:Class?scrollTo=sweep)}
* for the definition of this function.
*/

6
typings/index.d.ts vendored
View File

@ -878,6 +878,8 @@ export type CategoryChannelTypes = ExcludeEnum<
export class CategoryChannel extends GuildChannel {
public readonly children: Collection<Snowflake, Exclude<NonThreadGuildBasedChannel, CategoryChannel>>;
public static parent: null;
public parentId: null;
public type: 'GUILD_CATEGORY';
public createChannel<T extends Exclude<CategoryChannelTypes, 'GUILD_STORE' | ChannelTypes.GUILD_STORE>>(
@ -3140,7 +3142,7 @@ export class TextInputComponent extends BaseMessageComponent {
}
export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhooks', 'createWebhook', 'setNSFW']) {
private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client, fromInteraction?: boolean);
private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client);
public archived: boolean | null;
public readonly firstMessage: Message | null;
public readonly archivedAt: Date | null;
@ -7367,7 +7369,7 @@ export type GuildBasedChannel = Extract<AnyChannel, { guild: Guild }>;
export type NonThreadGuildBasedChannel = Exclude<GuildBasedChannel, ThreadChannel>;
export type GuildTextBasedChannel = Exclude<Extract<GuildBasedChannel, TextBasedChannel>, ForumChannel>;
export type GuildTextBasedChannel = Extract<GuildBasedChannel, TextBasedChannel>;
export type TextChannelResolvable = Snowflake | TextChannel;