mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
chore(Threads): general fixup and catch up on features (#5959)
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
const BaseManager = require('./BaseManager');
|
const BaseManager = require('./BaseManager');
|
||||||
const GuildChannel = require('../structures/GuildChannel');
|
const GuildChannel = require('../structures/GuildChannel');
|
||||||
const PermissionOverwrites = require('../structures/PermissionOverwrites');
|
const PermissionOverwrites = require('../structures/PermissionOverwrites');
|
||||||
|
const ThreadChannel = require('../structures/ThreadChannel');
|
||||||
const Collection = require('../util/Collection');
|
const Collection = require('../util/Collection');
|
||||||
const { ChannelTypes, ThreadChannelTypes } = require('../util/Constants');
|
const { ChannelTypes, ThreadChannelTypes } = require('../util/Constants');
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ class GuildChannelManager extends BaseManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The cache of this Manager
|
* The cache of this Manager
|
||||||
* @type {Collection<Snowflake, GuildChannel>}
|
* @type {Collection<Snowflake, GuildChannel|ThreadChannel>}
|
||||||
* @name GuildChannelManager#cache
|
* @name GuildChannelManager#cache
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -50,27 +51,30 @@ class GuildChannelManager extends BaseManager {
|
|||||||
/**
|
/**
|
||||||
* Data that can be resolved to give a Guild Channel object. This can be:
|
* Data that can be resolved to give a Guild Channel object. This can be:
|
||||||
* * A GuildChannel object
|
* * A GuildChannel object
|
||||||
|
* * A ThreadChannel object
|
||||||
* * A Snowflake
|
* * A Snowflake
|
||||||
* @typedef {GuildChannel|Snowflake} GuildChannelResolvable
|
* @typedef {GuildChannel|ThreadChannel|Snowflake} GuildChannelResolvable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a GuildChannelResolvable to a Channel object.
|
* Resolves a GuildChannelResolvable to a Channel object.
|
||||||
* @method resolve
|
|
||||||
* @memberof GuildChannelManager
|
|
||||||
* @instance
|
|
||||||
* @param {GuildChannelResolvable} channel The GuildChannel resolvable to resolve
|
* @param {GuildChannelResolvable} channel The GuildChannel resolvable to resolve
|
||||||
* @returns {?GuildChannel}
|
* @returns {?(GuildChannel|ThreadChannel)}
|
||||||
*/
|
*/
|
||||||
|
resolve(channel) {
|
||||||
|
if (channel instanceof ThreadChannel) return super.resolve(channel.id);
|
||||||
|
return super.resolve(channel);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a GuildChannelResolvable to a channel ID string.
|
* Resolves a GuildChannelResolvable to a channel ID string.
|
||||||
* @method resolveID
|
|
||||||
* @memberof GuildChannelManager
|
|
||||||
* @instance
|
|
||||||
* @param {GuildChannelResolvable} channel The GuildChannel resolvable to resolve
|
* @param {GuildChannelResolvable} channel The GuildChannel resolvable to resolve
|
||||||
* @returns {?Snowflake}
|
* @returns {?Snowflake}
|
||||||
*/
|
*/
|
||||||
|
resolveID(channel) {
|
||||||
|
if (channel instanceof ThreadChannel) return super.resolveID(channel.id);
|
||||||
|
return super.resolveID(channel);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options used to create a new channel in a guild.
|
* Options used to create a new channel in a guild.
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ class ThreadManager extends BaseManager {
|
|||||||
* A number that is allowed to be the duration in minutes before a thread is automatically archived. This can be:
|
* A number that is allowed to be the duration in minutes before a thread is automatically archived. This can be:
|
||||||
* * `60` (1 hour)
|
* * `60` (1 hour)
|
||||||
* * `1440` (1 day)
|
* * `1440` (1 day)
|
||||||
* * `4320` (3 days)
|
* * `4320` (3 days) <warn>This is only available when the guild has the `THREE_DAY_THREAD_ARCHIVE` feature.</warn>
|
||||||
* * `10080` (7 days)
|
* * `10080` (7 days) <warn>This is only available when the guild has the `SEVEN_DAY_THREAD_ARCHIVE` feature.</warn>
|
||||||
* @typedef {number} ThreadAutoArchiveDuration
|
* @typedef {number} ThreadAutoArchiveDuration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -76,8 +76,8 @@ class ThreadManager extends BaseManager {
|
|||||||
* @property {ThreadAutoArchiveDuration} autoArchiveDuration How long before the thread is automatically archived
|
* @property {ThreadAutoArchiveDuration} autoArchiveDuration How long before the thread is automatically archived
|
||||||
* @property {MessageResolvable} [startMessage] The message to start a public or news thread from,
|
* @property {MessageResolvable} [startMessage] The message to start a public or news thread from,
|
||||||
* creates a private thread if not provided
|
* creates a private thread if not provided
|
||||||
* @property {ThreadChannelType|number} [type] The type of thread to create
|
* @property {ThreadChannelType|number} [type='public_thread'] The type of thread to create
|
||||||
* <warn>When creating threads in a `news` channel this is always `news_thread`</warn>
|
* <warn>When creating threads in a `news` channel this is ignored and is always `news_thread`</warn>
|
||||||
* @param {string} [reason] Reason for creating the thread
|
* @param {string} [reason] Reason for creating the thread
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -89,16 +89,21 @@ class ThreadManager extends BaseManager {
|
|||||||
* // Create a new public thread
|
* // Create a new public thread
|
||||||
* channel.threads
|
* channel.threads
|
||||||
* .create({
|
* .create({
|
||||||
* name: 'food-talk'
|
* name: 'food-talk',
|
||||||
* autoArchiveDuration: 60,
|
* autoArchiveDuration: 60,
|
||||||
* startMessage: channel.lastMessageID,
|
|
||||||
* reason: 'Needed a separate thread for food',
|
* reason: 'Needed a separate thread for food',
|
||||||
* })
|
* })
|
||||||
* .then(console.log)
|
* .then(console.log)
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
|
* @example
|
||||||
* // Create a new private thread
|
* // Create a new private thread
|
||||||
* channel.threads
|
* channel.threads
|
||||||
* .create({ name: 'mod-talk', autoArchiveDuration: 60, reason: 'Needed a separate thread for moderation' })
|
* .create({
|
||||||
|
* name: 'mod-talk',
|
||||||
|
* autoArchiveDuration: 60,
|
||||||
|
* type: 'private_thread',
|
||||||
|
* reason: 'Needed a separate thread for moderation',
|
||||||
|
* })
|
||||||
* .then(console.log)
|
* .then(console.log)
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
@@ -113,7 +118,7 @@ class ThreadManager extends BaseManager {
|
|||||||
if (!startMessageID) throw new TypeError('INVALID_TYPE', 'startMessage', 'MessageResolvable');
|
if (!startMessageID) throw new TypeError('INVALID_TYPE', 'startMessage', 'MessageResolvable');
|
||||||
path = path.messages(startMessageID);
|
path = path.messages(startMessageID);
|
||||||
} else if (this.channel.type !== 'news') {
|
} else if (this.channel.type !== 'news') {
|
||||||
resolvedType = typeof type === 'string' ? ChannelTypes[type.toUpperCase()] : type;
|
resolvedType = typeof type === 'string' ? ChannelTypes[type.toUpperCase()] : type ?? resolvedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await path.threads.post({
|
const data = await path.threads.post({
|
||||||
|
|||||||
@@ -170,7 +170,10 @@ class Guild extends AnonymousGuild {
|
|||||||
* * NEWS
|
* * NEWS
|
||||||
* * PARTNERED
|
* * PARTNERED
|
||||||
* * PREVIEW_ENABLED
|
* * PREVIEW_ENABLED
|
||||||
|
* * PRIVATE_THREADS
|
||||||
* * RELAY_ENABLED
|
* * RELAY_ENABLED
|
||||||
|
* * SEVEN_DAY_THREAD_ARCHIVE
|
||||||
|
* * THREE_DAY_THREAD_ARCHIVE
|
||||||
* * TICKETED_EVENTS_ENABLED
|
* * TICKETED_EVENTS_ENABLED
|
||||||
* * VANITY_URL
|
* * VANITY_URL
|
||||||
* * VERIFIED
|
* * VERIFIED
|
||||||
|
|||||||
@@ -256,13 +256,13 @@ class GuildMember extends Base {
|
|||||||
/**
|
/**
|
||||||
* Returns `channel.permissionsFor(guildMember)`. Returns permissions for a member in a guild channel,
|
* Returns `channel.permissionsFor(guildMember)`. Returns permissions for a member in a guild channel,
|
||||||
* taking into account roles and permission overwrites.
|
* taking into account roles and permission overwrites.
|
||||||
* @param {ChannelResolvable} channel The guild channel to use as context
|
* @param {GuildChannelResolvable} channel The guild channel to use as context
|
||||||
* @returns {Readonly<Permissions>}
|
* @returns {Readonly<Permissions>}
|
||||||
*/
|
*/
|
||||||
permissionsIn(channel) {
|
permissionsIn(channel) {
|
||||||
channel = this.guild.channels.resolve(channel);
|
channel = this.guild.channels.resolve(channel);
|
||||||
if (!channel) throw new Error('GUILD_CHANNEL_RESOLVE');
|
if (!channel) throw new Error('GUILD_CHANNEL_RESOLVE');
|
||||||
return channel.memberPermissions(this);
|
return channel.permissionsFor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -764,6 +764,7 @@ exports.APIErrors = {
|
|||||||
ANNOUNCEMENT_EDIT_LIMIT_EXCEEDED: 20022,
|
ANNOUNCEMENT_EDIT_LIMIT_EXCEEDED: 20022,
|
||||||
CHANNEL_HIT_WRITE_RATELIMIT: 20028,
|
CHANNEL_HIT_WRITE_RATELIMIT: 20028,
|
||||||
CONTENT_NOT_ALLOWED: 20031,
|
CONTENT_NOT_ALLOWED: 20031,
|
||||||
|
GUILD_PREMIUM_LEVEL_TOO_LOW: 20035,
|
||||||
MAXIMUM_GUILDS: 30001,
|
MAXIMUM_GUILDS: 30001,
|
||||||
MAXIMUM_FRIENDS: 30002,
|
MAXIMUM_FRIENDS: 30002,
|
||||||
MAXIMUM_PINS: 30003,
|
MAXIMUM_PINS: 30003,
|
||||||
|
|||||||
14
typings/index.d.ts
vendored
14
typings/index.d.ts
vendored
@@ -1082,7 +1082,7 @@ declare module 'discord.js' {
|
|||||||
public deleteDM(): Promise<DMChannel>;
|
public deleteDM(): Promise<DMChannel>;
|
||||||
public edit(data: GuildMemberEditData, reason?: string): Promise<GuildMember>;
|
public edit(data: GuildMemberEditData, reason?: string): Promise<GuildMember>;
|
||||||
public kick(reason?: string): Promise<GuildMember>;
|
public kick(reason?: string): Promise<GuildMember>;
|
||||||
public permissionsIn(channel: ChannelResolvable): Readonly<Permissions>;
|
public permissionsIn(channel: GuildChannelResolvable): Readonly<Permissions>;
|
||||||
public setNickname(nickname: string | null, reason?: string): Promise<GuildMember>;
|
public setNickname(nickname: string | null, reason?: string): Promise<GuildMember>;
|
||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
@@ -2400,7 +2400,11 @@ declare module 'discord.js' {
|
|||||||
): Promise<Collection<Snowflake, ApplicationCommandPermissions[]>>;
|
): Promise<Collection<Snowflake, ApplicationCommandPermissions[]>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GuildChannelManager extends BaseManager<Snowflake, GuildChannel, GuildChannelResolvable> {
|
export class GuildChannelManager extends BaseManager<
|
||||||
|
Snowflake,
|
||||||
|
GuildChannel | ThreadChannel,
|
||||||
|
GuildChannelResolvable
|
||||||
|
> {
|
||||||
constructor(guild: Guild, iterable?: Iterable<any>);
|
constructor(guild: Guild, iterable?: Iterable<any>);
|
||||||
public readonly channelCountWithoutThreads: number;
|
public readonly channelCountWithoutThreads: number;
|
||||||
public guild: Guild;
|
public guild: Guild;
|
||||||
@@ -2740,6 +2744,7 @@ declare module 'discord.js' {
|
|||||||
ANNOUNCEMENT_EDIT_LIMIT_EXCEEDED: 20022;
|
ANNOUNCEMENT_EDIT_LIMIT_EXCEEDED: 20022;
|
||||||
CHANNEL_HIT_WRITE_RATELIMIT: 20028;
|
CHANNEL_HIT_WRITE_RATELIMIT: 20028;
|
||||||
CONTENT_NOT_ALLOWED: 20031;
|
CONTENT_NOT_ALLOWED: 20031;
|
||||||
|
GUILD_PREMIUM_LEVEL_TOO_LOW: 20035;
|
||||||
MAXIMUM_GUILDS: 30001;
|
MAXIMUM_GUILDS: 30001;
|
||||||
MAXIMUM_FRIENDS: 30002;
|
MAXIMUM_FRIENDS: 30002;
|
||||||
MAXIMUM_PINS: 30003;
|
MAXIMUM_PINS: 30003;
|
||||||
@@ -3372,7 +3377,7 @@ declare module 'discord.js' {
|
|||||||
type?: number;
|
type?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
type GuildChannelResolvable = Snowflake | GuildChannel;
|
type GuildChannelResolvable = Snowflake | GuildChannel | ThreadChannel;
|
||||||
|
|
||||||
interface GuildChannelCreateOptions {
|
interface GuildChannelCreateOptions {
|
||||||
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
|
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
|
||||||
@@ -3466,7 +3471,10 @@ declare module 'discord.js' {
|
|||||||
| 'NEWS'
|
| 'NEWS'
|
||||||
| 'PARTNERED'
|
| 'PARTNERED'
|
||||||
| 'PREVIEW_ENABLED'
|
| 'PREVIEW_ENABLED'
|
||||||
|
| 'PRIVATE_THREADS'
|
||||||
| 'RELAY_ENABLED'
|
| 'RELAY_ENABLED'
|
||||||
|
| 'SEVEN_DAY_THREAD_ARCHIVE'
|
||||||
|
| 'THREE_DAY_THREAD_ARCHIVE'
|
||||||
| 'TICKETED_EVENTS_ENABLED'
|
| 'TICKETED_EVENTS_ENABLED'
|
||||||
| 'VANITY_URL'
|
| 'VANITY_URL'
|
||||||
| 'VERIFIED'
|
| 'VERIFIED'
|
||||||
|
|||||||
Reference in New Issue
Block a user