mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
feat: Add media channels (#9662)
* feat: add media channels * refactor: rename to `ThreadOnlyChannel` * feat: support media channels more * docs(ThreadOnlyChannel): update class description * types: update references * test: add more tests * chore: update code * refactor: `abstract` Co-authored-by: space <spaceeec@yahoo.com> --------- Co-authored-by: space <spaceeec@yahoo.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,7 @@ const allowedChannelTypes = [
|
|||||||
ChannelType.PrivateThread,
|
ChannelType.PrivateThread,
|
||||||
ChannelType.GuildStageVoice,
|
ChannelType.GuildStageVoice,
|
||||||
ChannelType.GuildForum,
|
ChannelType.GuildForum,
|
||||||
|
ChannelType.GuildMedia,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class WebhooksUpdate extends Action {
|
|||||||
/**
|
/**
|
||||||
* Emitted whenever a channel has its webhooks changed.
|
* Emitted whenever a channel has its webhooks changed.
|
||||||
* @event Client#webhooksUpdate
|
* @event Client#webhooksUpdate
|
||||||
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel
|
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel} channel
|
||||||
* The channel that had a webhook update
|
* The channel that had a webhook update
|
||||||
*/
|
*/
|
||||||
client.emit('webhooksUpdate', channel);
|
client.emit('webhooksUpdate', channel);
|
||||||
@@ -23,7 +23,7 @@ class WebhooksUpdate extends Action {
|
|||||||
/**
|
/**
|
||||||
* Emitted whenever a channel has its webhooks changed.
|
* Emitted whenever a channel has its webhooks changed.
|
||||||
* @event Client#webhookUpdate
|
* @event Client#webhookUpdate
|
||||||
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel
|
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel} channel
|
||||||
* The channel that had a webhook update
|
* The channel that had a webhook update
|
||||||
* @deprecated Use {@link Client#event:webhooksUpdate} instead.
|
* @deprecated Use {@link Client#event:webhooksUpdate} instead.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ exports.Message = require('./structures/Message').Message;
|
|||||||
exports.Attachment = require('./structures/Attachment');
|
exports.Attachment = require('./structures/Attachment');
|
||||||
exports.AttachmentBuilder = require('./structures/AttachmentBuilder');
|
exports.AttachmentBuilder = require('./structures/AttachmentBuilder');
|
||||||
exports.ModalBuilder = require('./structures/ModalBuilder');
|
exports.ModalBuilder = require('./structures/ModalBuilder');
|
||||||
|
exports.MediaChannel = require('./structures/MediaChannel');
|
||||||
exports.MessageCollector = require('./structures/MessageCollector');
|
exports.MessageCollector = require('./structures/MessageCollector');
|
||||||
exports.MessageComponentInteraction = require('./structures/MessageComponentInteraction');
|
exports.MessageComponentInteraction = require('./structures/MessageComponentInteraction');
|
||||||
exports.MessageContextMenuCommandInteraction = require('./structures/MessageContextMenuCommandInteraction');
|
exports.MessageContextMenuCommandInteraction = require('./structures/MessageContextMenuCommandInteraction');
|
||||||
@@ -199,6 +200,7 @@ exports.TextInputBuilder = require('./structures/TextInputBuilder');
|
|||||||
exports.TextInputComponent = require('./structures/TextInputComponent');
|
exports.TextInputComponent = require('./structures/TextInputComponent');
|
||||||
exports.ThreadChannel = require('./structures/ThreadChannel');
|
exports.ThreadChannel = require('./structures/ThreadChannel');
|
||||||
exports.ThreadMember = require('./structures/ThreadMember');
|
exports.ThreadMember = require('./structures/ThreadMember');
|
||||||
|
exports.ThreadOnlyChannel = require('./structures/ThreadOnlyChannel');
|
||||||
exports.Typing = require('./structures/Typing');
|
exports.Typing = require('./structures/Typing');
|
||||||
exports.User = require('./structures/User');
|
exports.User = require('./structures/User');
|
||||||
exports.UserContextMenuCommandInteraction = require('./structures/UserContextMenuCommandInteraction');
|
exports.UserContextMenuCommandInteraction = require('./structures/UserContextMenuCommandInteraction');
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ class GuildChannelManager extends CachedManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {ChannelWebhookCreateOptions} WebhookCreateOptions
|
* @typedef {ChannelWebhookCreateOptions} WebhookCreateOptions
|
||||||
* @property {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|Snowflake} channel
|
* @property {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel|Snowflake} channel
|
||||||
* The channel to create the webhook for
|
* The channel to create the webhook for
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,9 @@ class GuildInviteManager extends CachedManager {
|
|||||||
* * NewsChannel
|
* * NewsChannel
|
||||||
* * StageChannel
|
* * StageChannel
|
||||||
* * ForumChannel
|
* * ForumChannel
|
||||||
|
* * MediaChannel
|
||||||
* * Snowflake
|
* * Snowflake
|
||||||
* @typedef {TextChannel|VoiceChannel|NewsChannel|StageChannel|ForumChannel|Snowflake}
|
* @typedef {TextChannel|VoiceChannel|NewsChannel|StageChannel|ForumChannel|MediaChannel|Snowflake}
|
||||||
* GuildInvitableChannelResolvable
|
* GuildInvitableChannelResolvable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class ThreadManager extends CachedManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel this Manager belongs to
|
* The channel this Manager belongs to
|
||||||
* @type {TextChannel|NewsChannel|ForumChannel}
|
* @type {TextChannel|NewsChannel|ForumChannel|MediaChannel}
|
||||||
*/
|
*/
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class AutoModerationActionExecution {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel where this action was triggered from.
|
* The channel where this action was triggered from.
|
||||||
* @type {?(GuildTextBasedChannel|ForumChannel)}
|
* @type {?(GuildTextBasedChannel|ForumChannel|MediaChannel)}
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
get channel() {
|
get channel() {
|
||||||
|
|||||||
@@ -1,139 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const GuildChannel = require('./GuildChannel');
|
const ThreadOnlyChannel = require('./ThreadOnlyChannel');
|
||||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
|
||||||
const GuildForumThreadManager = require('../managers/GuildForumThreadManager');
|
|
||||||
const { transformAPIGuildForumTag, transformAPIGuildDefaultReaction } = require('../util/Channels');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} GuildForumTagEmoji
|
* Represents a forum channel.
|
||||||
* @property {?Snowflake} id The id of a guild's custom emoji
|
* @extends {ThreadOnlyChannel}
|
||||||
* @property {?string} name The unicode character of the emoji
|
|
||||||
*/
|
*/
|
||||||
|
class ForumChannel extends ThreadOnlyChannel {
|
||||||
/**
|
|
||||||
* @typedef {Object} GuildForumTag
|
|
||||||
* @property {Snowflake} id The id of the tag
|
|
||||||
* @property {string} name The name of the tag
|
|
||||||
* @property {boolean} moderated Whether this tag can only be added to or removed from threads
|
|
||||||
* by a member with the `ManageThreads` permission
|
|
||||||
* @property {?GuildForumTagEmoji} emoji The emoji of this tag
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} GuildForumTagData
|
|
||||||
* @property {Snowflake} [id] The id of the tag
|
|
||||||
* @property {string} name The name of the tag
|
|
||||||
* @property {boolean} [moderated] Whether this tag can only be added to or removed from threads
|
|
||||||
* by a member with the `ManageThreads` permission
|
|
||||||
* @property {?GuildForumTagEmoji} [emoji] The emoji of this tag
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} DefaultReactionEmoji
|
|
||||||
* @property {?Snowflake} id The id of a guild's custom emoji
|
|
||||||
* @property {?string} name The unicode character of the emoji
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a channel that only contains threads
|
|
||||||
* @extends {GuildChannel}
|
|
||||||
* @implements {TextBasedChannel}
|
|
||||||
*/
|
|
||||||
class ForumChannel extends GuildChannel {
|
|
||||||
constructor(guild, data, client) {
|
|
||||||
super(guild, data, client, false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A manager of the threads belonging to this channel
|
|
||||||
* @type {GuildForumThreadManager}
|
|
||||||
*/
|
|
||||||
this.threads = new GuildForumThreadManager(this);
|
|
||||||
|
|
||||||
this._patch(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
_patch(data) {
|
_patch(data) {
|
||||||
super._patch(data);
|
super._patch(data);
|
||||||
if ('available_tags' in data) {
|
|
||||||
/**
|
|
||||||
* The set of tags that can be used in this channel.
|
|
||||||
* @type {GuildForumTag[]}
|
|
||||||
*/
|
|
||||||
this.availableTags = data.available_tags.map(tag => transformAPIGuildForumTag(tag));
|
|
||||||
} else {
|
|
||||||
this.availableTags ??= [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('default_reaction_emoji' in data) {
|
|
||||||
/**
|
|
||||||
* The emoji to show in the add reaction button on a thread in a guild forum channel
|
|
||||||
* @type {?DefaultReactionEmoji}
|
|
||||||
*/
|
|
||||||
this.defaultReactionEmoji = data.default_reaction_emoji
|
|
||||||
? transformAPIGuildDefaultReaction(data.default_reaction_emoji)
|
|
||||||
: null;
|
|
||||||
} else {
|
|
||||||
this.defaultReactionEmoji ??= null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('default_thread_rate_limit_per_user' in data) {
|
|
||||||
/**
|
|
||||||
* The initial rate limit per user (slowmode) to set on newly created threads in a channel.
|
|
||||||
* @type {?number}
|
|
||||||
*/
|
|
||||||
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user;
|
|
||||||
} else {
|
|
||||||
this.defaultThreadRateLimitPerUser ??= null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('rate_limit_per_user' in data) {
|
|
||||||
/**
|
|
||||||
* The rate limit per user (slowmode) for this channel.
|
|
||||||
* @type {?number}
|
|
||||||
*/
|
|
||||||
this.rateLimitPerUser = data.rate_limit_per_user;
|
|
||||||
} else {
|
|
||||||
this.rateLimitPerUser ??= null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('default_auto_archive_duration' in data) {
|
|
||||||
/**
|
|
||||||
* The default auto archive duration for newly created threads in this channel.
|
|
||||||
* @type {?ThreadAutoArchiveDuration}
|
|
||||||
*/
|
|
||||||
this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
|
|
||||||
} else {
|
|
||||||
this.defaultAutoArchiveDuration ??= null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('nsfw' in data) {
|
|
||||||
/**
|
|
||||||
* If this channel is considered NSFW.
|
|
||||||
* @type {boolean}
|
|
||||||
*/
|
|
||||||
this.nsfw = data.nsfw;
|
|
||||||
} else {
|
|
||||||
this.nsfw ??= false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('topic' in data) {
|
|
||||||
/**
|
|
||||||
* The topic of this channel.
|
|
||||||
* @type {?string}
|
|
||||||
*/
|
|
||||||
this.topic = data.topic;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('default_sort_order' in data) {
|
|
||||||
/**
|
|
||||||
* The default sort order mode used to order posts
|
|
||||||
* @type {?SortOrderType}
|
|
||||||
*/
|
|
||||||
this.defaultSortOrder = data.default_sort_order;
|
|
||||||
} else {
|
|
||||||
this.defaultSortOrder ??= null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default layout type used to display posts
|
* The default layout type used to display posts
|
||||||
@@ -142,95 +17,6 @@ class ForumChannel extends GuildChannel {
|
|||||||
this.defaultForumLayout = data.default_forum_layout;
|
this.defaultForumLayout = data.default_forum_layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the available tags for this forum channel
|
|
||||||
* @param {GuildForumTagData[]} availableTags The tags to set as available in this channel
|
|
||||||
* @param {string} [reason] Reason for changing the available tags
|
|
||||||
* @returns {Promise<ForumChannel>}
|
|
||||||
*/
|
|
||||||
setAvailableTags(availableTags, reason) {
|
|
||||||
return this.edit({ availableTags, reason });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the default reaction emoji for this channel
|
|
||||||
* @param {?DefaultReactionEmoji} defaultReactionEmoji The emoji to set as the default reaction emoji
|
|
||||||
* @param {string} [reason] Reason for changing the default reaction emoji
|
|
||||||
* @returns {Promise<ForumChannel>}
|
|
||||||
*/
|
|
||||||
setDefaultReactionEmoji(defaultReactionEmoji, reason) {
|
|
||||||
return this.edit({ defaultReactionEmoji, reason });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the default rate limit per user (slowmode) for new threads in this channel
|
|
||||||
* @param {number} defaultThreadRateLimitPerUser The rate limit to set on newly created threads in this channel
|
|
||||||
* @param {string} [reason] Reason for changing the default rate limit
|
|
||||||
* @returns {Promise<ForumChannel>}
|
|
||||||
*/
|
|
||||||
setDefaultThreadRateLimitPerUser(defaultThreadRateLimitPerUser, reason) {
|
|
||||||
return this.edit({ defaultThreadRateLimitPerUser, reason });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an invite to this guild channel.
|
|
||||||
* @param {InviteCreateOptions} [options={}] The options for creating the invite
|
|
||||||
* @returns {Promise<Invite>}
|
|
||||||
* @example
|
|
||||||
* // Create an invite to a channel
|
|
||||||
* channel.createInvite()
|
|
||||||
* .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
|
|
||||||
* .catch(console.error);
|
|
||||||
*/
|
|
||||||
createInvite(options) {
|
|
||||||
return this.guild.invites.create(this.id, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches a collection of invites to this guild channel.
|
|
||||||
* Resolves with a collection mapping invites by their codes.
|
|
||||||
* @param {boolean} [cache=true] Whether to cache the fetched invites
|
|
||||||
* @returns {Promise<Collection<string, Invite>>}
|
|
||||||
*/
|
|
||||||
fetchInvites(cache) {
|
|
||||||
return this.guild.invites.fetch({ channelId: this.id, cache });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the default auto archive duration for all newly created threads in this channel.
|
|
||||||
* @param {ThreadAutoArchiveDuration} defaultAutoArchiveDuration The new default auto archive duration
|
|
||||||
* @param {string} [reason] Reason for changing the channel's default auto archive duration
|
|
||||||
* @returns {Promise<ForumChannel>}
|
|
||||||
*/
|
|
||||||
setDefaultAutoArchiveDuration(defaultAutoArchiveDuration, reason) {
|
|
||||||
return this.edit({ defaultAutoArchiveDuration, reason });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a new topic for the guild channel.
|
|
||||||
* @param {?string} topic The new topic for the guild channel
|
|
||||||
* @param {string} [reason] Reason for changing the guild channel's topic
|
|
||||||
* @returns {Promise<ForumChannel>}
|
|
||||||
* @example
|
|
||||||
* // Set a new channel topic
|
|
||||||
* channel.setTopic('needs more rate limiting')
|
|
||||||
* .then(newChannel => console.log(`Channel's new topic is ${newChannel.topic}`))
|
|
||||||
* .catch(console.error);
|
|
||||||
*/
|
|
||||||
setTopic(topic, reason) {
|
|
||||||
return this.edit({ topic, reason });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the default sort order mode used to order posts
|
|
||||||
* @param {?SortOrderType} defaultSortOrder The default sort order mode to set on this channel
|
|
||||||
* @param {string} [reason] Reason for changing the default sort order
|
|
||||||
* @returns {Promise<ForumChannel>}
|
|
||||||
*/
|
|
||||||
setDefaultSortOrder(defaultSortOrder, reason) {
|
|
||||||
return this.edit({ defaultSortOrder, reason });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default forum layout type used to display posts
|
* Sets the default forum layout type used to display posts
|
||||||
* @param {ForumLayoutType} defaultForumLayout The default forum layout type to set on this channel
|
* @param {ForumLayoutType} defaultForumLayout The default forum layout type to set on this channel
|
||||||
@@ -240,25 +26,6 @@ class ForumChannel extends GuildChannel {
|
|||||||
setDefaultForumLayout(defaultForumLayout, reason) {
|
setDefaultForumLayout(defaultForumLayout, reason) {
|
||||||
return this.edit({ defaultForumLayout, reason });
|
return this.edit({ defaultForumLayout, reason });
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
|
||||||
/* eslint-disable no-empty-function */
|
|
||||||
createWebhook() {}
|
|
||||||
fetchWebhooks() {}
|
|
||||||
setNSFW() {}
|
|
||||||
setRateLimitPerUser() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextBasedChannel.applyToClass(ForumChannel, true, [
|
|
||||||
'send',
|
|
||||||
'lastMessage',
|
|
||||||
'lastPinAt',
|
|
||||||
'bulkDelete',
|
|
||||||
'sendTyping',
|
|
||||||
'createMessageCollector',
|
|
||||||
'awaitMessages',
|
|
||||||
'createMessageComponentCollector',
|
|
||||||
'awaitMessageComponent',
|
|
||||||
]);
|
|
||||||
|
|
||||||
module.exports = ForumChannel;
|
module.exports = ForumChannel;
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ class Guild extends AnonymousGuild {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Widget channel for this guild
|
* Widget channel for this guild
|
||||||
* @type {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel)}
|
* @type {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel)}
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
get widgetChannel() {
|
get widgetChannel() {
|
||||||
@@ -693,14 +693,15 @@ class Guild extends AnonymousGuild {
|
|||||||
* Data for the Guild Widget Settings object
|
* Data for the Guild Widget Settings object
|
||||||
* @typedef {Object} GuildWidgetSettings
|
* @typedef {Object} GuildWidgetSettings
|
||||||
* @property {boolean} enabled Whether the widget is enabled
|
* @property {boolean} enabled Whether the widget is enabled
|
||||||
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel)} channel The widget invite channel
|
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel)} channel
|
||||||
|
* The widget invite channel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Guild Widget Settings object
|
* The Guild Widget Settings object
|
||||||
* @typedef {Object} GuildWidgetSettingsData
|
* @typedef {Object} GuildWidgetSettingsData
|
||||||
* @property {boolean} enabled Whether the widget is enabled
|
* @property {boolean} enabled Whether the widget is enabled
|
||||||
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|Snowflake)} channel
|
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel|Snowflake)} channel
|
||||||
* The widget invite channel
|
* The widget invite channel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -884,7 +885,8 @@ class Guild extends AnonymousGuild {
|
|||||||
* Welcome channel data
|
* Welcome channel data
|
||||||
* @typedef {Object} WelcomeChannelData
|
* @typedef {Object} WelcomeChannelData
|
||||||
* @property {string} description The description to show for this welcome channel
|
* @property {string} description The description to show for this welcome channel
|
||||||
* @property {TextChannel|NewsChannel|ForumChannel|Snowflake} channel The channel to link for this welcome channel
|
* @property {TextChannel|NewsChannel|ForumChannel|MediaChannel|Snowflake} channel
|
||||||
|
* The channel to link for this welcome channel
|
||||||
* @property {EmojiIdentifierResolvable} [emoji] The emoji to display for this welcome channel
|
* @property {EmojiIdentifierResolvable} [emoji] The emoji to display for this welcome channel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const { getSortableGroupTypes } = require('../util/Util');
|
|||||||
* - {@link NewsChannel}
|
* - {@link NewsChannel}
|
||||||
* - {@link StageChannel}
|
* - {@link StageChannel}
|
||||||
* - {@link ForumChannel}
|
* - {@link ForumChannel}
|
||||||
|
* - {@link MediaChannel}
|
||||||
* @extends {BaseChannel}
|
* @extends {BaseChannel}
|
||||||
* @abstract
|
* @abstract
|
||||||
*/
|
*/
|
||||||
|
|||||||
11
packages/discord.js/src/structures/MediaChannel.js
Normal file
11
packages/discord.js/src/structures/MediaChannel.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const ThreadOnlyChannel = require('./ThreadOnlyChannel');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a media channel.
|
||||||
|
* @extends {ThreadOnlyChannel}
|
||||||
|
*/
|
||||||
|
class MediaChannel extends ThreadOnlyChannel {}
|
||||||
|
|
||||||
|
module.exports = MediaChannel;
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { lazy } = require('@discordjs/util');
|
||||||
const { ChannelType, PermissionFlagsBits, Routes, ChannelFlags } = require('discord-api-types/v10');
|
const { ChannelType, PermissionFlagsBits, Routes, ChannelFlags } = require('discord-api-types/v10');
|
||||||
const { BaseChannel } = require('./BaseChannel');
|
const { BaseChannel } = require('./BaseChannel');
|
||||||
|
const getThreadOnlyChannel = lazy(() => require('./ThreadOnlyChannel'));
|
||||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||||
const { DiscordjsRangeError, ErrorCodes } = require('../errors');
|
const { DiscordjsRangeError, ErrorCodes } = require('../errors');
|
||||||
const GuildMessageManager = require('../managers/GuildMessageManager');
|
const GuildMessageManager = require('../managers/GuildMessageManager');
|
||||||
@@ -248,7 +250,7 @@ class ThreadChannel extends BaseChannel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The parent channel of this thread
|
* The parent channel of this thread
|
||||||
* @type {?(NewsChannel|TextChannel|ForumChannel)}
|
* @type {?(NewsChannel|TextChannel|ForumChannel|MediaChannel)}
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
get parent() {
|
get parent() {
|
||||||
@@ -312,7 +314,7 @@ class ThreadChannel extends BaseChannel {
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line require-await
|
// eslint-disable-next-line require-await
|
||||||
async fetchStarterMessage(options) {
|
async fetchStarterMessage(options) {
|
||||||
const channel = this.parent?.type === ChannelType.GuildForum ? this : this.parent;
|
const channel = this.parent instanceof getThreadOnlyChannel() ? this : this.parent;
|
||||||
return channel?.messages.fetch({ message: this.id, ...options }) ?? null;
|
return channel?.messages.fetch({ message: this.id, ...options }) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
249
packages/discord.js/src/structures/ThreadOnlyChannel.js
Normal file
249
packages/discord.js/src/structures/ThreadOnlyChannel.js
Normal file
@@ -0,0 +1,249 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const GuildChannel = require('./GuildChannel');
|
||||||
|
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||||
|
const GuildForumThreadManager = require('../managers/GuildForumThreadManager');
|
||||||
|
const { transformAPIGuildForumTag, transformAPIGuildDefaultReaction } = require('../util/Channels');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} GuildForumTagEmoji
|
||||||
|
* @property {?Snowflake} id The id of a guild's custom emoji
|
||||||
|
* @property {?string} name The unicode character of the emoji
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} GuildForumTag
|
||||||
|
* @property {Snowflake} id The id of the tag
|
||||||
|
* @property {string} name The name of the tag
|
||||||
|
* @property {boolean} moderated Whether this tag can only be added to or removed from threads
|
||||||
|
* by a member with the `ManageThreads` permission
|
||||||
|
* @property {?GuildForumTagEmoji} emoji The emoji of this tag
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} GuildForumTagData
|
||||||
|
* @property {Snowflake} [id] The id of the tag
|
||||||
|
* @property {string} name The name of the tag
|
||||||
|
* @property {boolean} [moderated] Whether this tag can only be added to or removed from threads
|
||||||
|
* by a member with the `ManageThreads` permission
|
||||||
|
* @property {?GuildForumTagEmoji} [emoji] The emoji of this tag
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} DefaultReactionEmoji
|
||||||
|
* @property {?Snowflake} id The id of a guild's custom emoji
|
||||||
|
* @property {?string} name The unicode character of the emoji
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents symbols utilised by thread-only channels.
|
||||||
|
* @extends {GuildChannel}
|
||||||
|
* @implements {TextBasedChannel}
|
||||||
|
* @abstract
|
||||||
|
*/
|
||||||
|
class ThreadOnlyChannel extends GuildChannel {
|
||||||
|
constructor(guild, data, client) {
|
||||||
|
super(guild, data, client, false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A manager of the threads belonging to this channel
|
||||||
|
* @type {GuildForumThreadManager}
|
||||||
|
*/
|
||||||
|
this.threads = new GuildForumThreadManager(this);
|
||||||
|
|
||||||
|
this._patch(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
_patch(data) {
|
||||||
|
super._patch(data);
|
||||||
|
if ('available_tags' in data) {
|
||||||
|
/**
|
||||||
|
* The set of tags that can be used in this channel.
|
||||||
|
* @type {GuildForumTag[]}
|
||||||
|
*/
|
||||||
|
this.availableTags = data.available_tags.map(tag => transformAPIGuildForumTag(tag));
|
||||||
|
} else {
|
||||||
|
this.availableTags ??= [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('default_reaction_emoji' in data) {
|
||||||
|
/**
|
||||||
|
* The emoji to show in the add reaction button on a thread in a guild forum channel
|
||||||
|
* @type {?DefaultReactionEmoji}
|
||||||
|
*/
|
||||||
|
this.defaultReactionEmoji = data.default_reaction_emoji
|
||||||
|
? transformAPIGuildDefaultReaction(data.default_reaction_emoji)
|
||||||
|
: null;
|
||||||
|
} else {
|
||||||
|
this.defaultReactionEmoji ??= null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('default_thread_rate_limit_per_user' in data) {
|
||||||
|
/**
|
||||||
|
* The initial rate limit per user (slowmode) to set on newly created threads in a channel.
|
||||||
|
* @type {?number}
|
||||||
|
*/
|
||||||
|
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user;
|
||||||
|
} else {
|
||||||
|
this.defaultThreadRateLimitPerUser ??= null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('rate_limit_per_user' in data) {
|
||||||
|
/**
|
||||||
|
* The rate limit per user (slowmode) for this channel.
|
||||||
|
* @type {?number}
|
||||||
|
*/
|
||||||
|
this.rateLimitPerUser = data.rate_limit_per_user;
|
||||||
|
} else {
|
||||||
|
this.rateLimitPerUser ??= null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('default_auto_archive_duration' in data) {
|
||||||
|
/**
|
||||||
|
* The default auto archive duration for newly created threads in this channel.
|
||||||
|
* @type {?ThreadAutoArchiveDuration}
|
||||||
|
*/
|
||||||
|
this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
|
||||||
|
} else {
|
||||||
|
this.defaultAutoArchiveDuration ??= null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('nsfw' in data) {
|
||||||
|
/**
|
||||||
|
* If this channel is considered NSFW.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.nsfw = data.nsfw;
|
||||||
|
} else {
|
||||||
|
this.nsfw ??= false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('topic' in data) {
|
||||||
|
/**
|
||||||
|
* The topic of this channel.
|
||||||
|
* @type {?string}
|
||||||
|
*/
|
||||||
|
this.topic = data.topic;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('default_sort_order' in data) {
|
||||||
|
/**
|
||||||
|
* The default sort order mode used to order posts
|
||||||
|
* @type {?SortOrderType}
|
||||||
|
*/
|
||||||
|
this.defaultSortOrder = data.default_sort_order;
|
||||||
|
} else {
|
||||||
|
this.defaultSortOrder ??= null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the available tags for this forum channel
|
||||||
|
* @param {GuildForumTagData[]} availableTags The tags to set as available in this channel
|
||||||
|
* @param {string} [reason] Reason for changing the available tags
|
||||||
|
* @returns {Promise<this>}
|
||||||
|
*/
|
||||||
|
setAvailableTags(availableTags, reason) {
|
||||||
|
return this.edit({ availableTags, reason });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the default reaction emoji for this channel
|
||||||
|
* @param {?DefaultReactionEmoji} defaultReactionEmoji The emoji to set as the default reaction emoji
|
||||||
|
* @param {string} [reason] Reason for changing the default reaction emoji
|
||||||
|
* @returns {Promise<this>}
|
||||||
|
*/
|
||||||
|
setDefaultReactionEmoji(defaultReactionEmoji, reason) {
|
||||||
|
return this.edit({ defaultReactionEmoji, reason });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the default rate limit per user (slowmode) for new threads in this channel
|
||||||
|
* @param {number} defaultThreadRateLimitPerUser The rate limit to set on newly created threads in this channel
|
||||||
|
* @param {string} [reason] Reason for changing the default rate limit
|
||||||
|
* @returns {Promise<this>}
|
||||||
|
*/
|
||||||
|
setDefaultThreadRateLimitPerUser(defaultThreadRateLimitPerUser, reason) {
|
||||||
|
return this.edit({ defaultThreadRateLimitPerUser, reason });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an invite to this guild channel.
|
||||||
|
* @param {InviteCreateOptions} [options={}] The options for creating the invite
|
||||||
|
* @returns {Promise<Invite>}
|
||||||
|
* @example
|
||||||
|
* // Create an invite to a channel
|
||||||
|
* channel.createInvite()
|
||||||
|
* .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
|
||||||
|
* .catch(console.error);
|
||||||
|
*/
|
||||||
|
createInvite(options) {
|
||||||
|
return this.guild.invites.create(this.id, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches a collection of invites to this guild channel.
|
||||||
|
* Resolves with a collection mapping invites by their codes.
|
||||||
|
* @param {boolean} [cache=true] Whether to cache the fetched invites
|
||||||
|
* @returns {Promise<Collection<string, Invite>>}
|
||||||
|
*/
|
||||||
|
fetchInvites(cache) {
|
||||||
|
return this.guild.invites.fetch({ channelId: this.id, cache });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the default auto archive duration for all newly created threads in this channel.
|
||||||
|
* @param {ThreadAutoArchiveDuration} defaultAutoArchiveDuration The new default auto archive duration
|
||||||
|
* @param {string} [reason] Reason for changing the channel's default auto archive duration
|
||||||
|
* @returns {Promise<this>}
|
||||||
|
*/
|
||||||
|
setDefaultAutoArchiveDuration(defaultAutoArchiveDuration, reason) {
|
||||||
|
return this.edit({ defaultAutoArchiveDuration, reason });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new topic for the guild channel.
|
||||||
|
* @param {?string} topic The new topic for the guild channel
|
||||||
|
* @param {string} [reason] Reason for changing the guild channel's topic
|
||||||
|
* @returns {Promise<this>}
|
||||||
|
* @example
|
||||||
|
* // Set a new channel topic
|
||||||
|
* channel.setTopic('needs more rate limiting')
|
||||||
|
* .then(newChannel => console.log(`Channel's new topic is ${newChannel.topic}`))
|
||||||
|
* .catch(console.error);
|
||||||
|
*/
|
||||||
|
setTopic(topic, reason) {
|
||||||
|
return this.edit({ topic, reason });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the default sort order mode used to order posts
|
||||||
|
* @param {?SortOrderType} defaultSortOrder The default sort order mode to set on this channel
|
||||||
|
* @param {string} [reason] Reason for changing the default sort order
|
||||||
|
* @returns {Promise<this>}
|
||||||
|
*/
|
||||||
|
setDefaultSortOrder(defaultSortOrder, reason) {
|
||||||
|
return this.edit({ defaultSortOrder, reason });
|
||||||
|
}
|
||||||
|
|
||||||
|
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||||
|
/* eslint-disable no-empty-function */
|
||||||
|
createWebhook() {}
|
||||||
|
fetchWebhooks() {}
|
||||||
|
setNSFW() {}
|
||||||
|
setRateLimitPerUser() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
TextBasedChannel.applyToClass(ThreadOnlyChannel, true, [
|
||||||
|
'send',
|
||||||
|
'lastMessage',
|
||||||
|
'lastPinAt',
|
||||||
|
'bulkDelete',
|
||||||
|
'sendTyping',
|
||||||
|
'createMessageCollector',
|
||||||
|
'awaitMessages',
|
||||||
|
'createMessageComponentCollector',
|
||||||
|
'awaitMessageComponent',
|
||||||
|
]);
|
||||||
|
|
||||||
|
module.exports = ThreadOnlyChannel;
|
||||||
@@ -147,7 +147,7 @@ class Webhook {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel the webhook belongs to
|
* The channel the webhook belongs to
|
||||||
* @type {?(TextChannel|VoiceChannel|StageChannel|NewsChannel|ForumChannel)}
|
* @type {?(TextChannel|VoiceChannel|StageChannel|NewsChannel|ForumChannel|MediaChannel)}
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
get channel() {
|
get channel() {
|
||||||
@@ -264,7 +264,7 @@ class Webhook {
|
|||||||
* @typedef {Object} WebhookEditOptions
|
* @typedef {Object} WebhookEditOptions
|
||||||
* @property {string} [name=this.name] The new name for the webhook
|
* @property {string} [name=this.name] The new name for the webhook
|
||||||
* @property {?(BufferResolvable)} [avatar] The new avatar for the webhook
|
* @property {?(BufferResolvable)} [avatar] The new avatar for the webhook
|
||||||
* @property {GuildTextChannelResolvable|VoiceChannel|StageChannel|ForumChannel} [channel]
|
* @property {GuildTextChannelResolvable|VoiceChannel|StageChannel|ForumChannel|MediaChannel} [channel]
|
||||||
* The new channel for the webhook
|
* The new channel for the webhook
|
||||||
* @property {string} [reason] Reason for editing the webhook
|
* @property {string} [reason] Reason for editing the webhook
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class WelcomeChannel extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel of this welcome channel
|
* The channel of this welcome channel
|
||||||
* @type {?(TextChannel|NewsChannel|ForumChannel)}
|
* @type {?(TextChannel|NewsChannel|ForumChannel|MediaChannel)}
|
||||||
*/
|
*/
|
||||||
get channel() {
|
get channel() {
|
||||||
return this.client.channels.resolve(this.channelId);
|
return this.client.channels.resolve(this.channelId);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const getVoiceChannel = lazy(() => require('../structures/VoiceChannel'));
|
|||||||
const getDirectoryChannel = lazy(() => require('../structures/DirectoryChannel'));
|
const getDirectoryChannel = lazy(() => require('../structures/DirectoryChannel'));
|
||||||
const getPartialGroupDMChannel = lazy(() => require('../structures/PartialGroupDMChannel'));
|
const getPartialGroupDMChannel = lazy(() => require('../structures/PartialGroupDMChannel'));
|
||||||
const getForumChannel = lazy(() => require('../structures/ForumChannel'));
|
const getForumChannel = lazy(() => require('../structures/ForumChannel'));
|
||||||
|
const getMediaChannel = lazy(() => require('../structures/MediaChannel'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a discord.js channel from data received from the API.
|
* Creates a discord.js channel from data received from the API.
|
||||||
@@ -69,6 +70,9 @@ function createChannel(client, data, guild, { allowUnknownGuild } = {}) {
|
|||||||
case ChannelType.GuildForum:
|
case ChannelType.GuildForum:
|
||||||
channel = new (getForumChannel())(guild, data, client);
|
channel = new (getForumChannel())(guild, data, client);
|
||||||
break;
|
break;
|
||||||
|
case ChannelType.GuildMedia:
|
||||||
|
channel = new (getMediaChannel())(guild, data, client);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (channel && !allowUnknownGuild) guild.channels?.cache.set(channel.id, channel);
|
if (channel && !allowUnknownGuild) guild.channels?.cache.set(channel.id, channel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,7 +163,13 @@ function makePlainError(err) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const TextSortableGroupTypes = [ChannelType.GuildText, ChannelType.GuildAnnouncement, ChannelType.GuildForum];
|
const TextSortableGroupTypes = [
|
||||||
|
ChannelType.GuildText,
|
||||||
|
ChannelType.GuildAnnouncement,
|
||||||
|
ChannelType.GuildForum,
|
||||||
|
ChannelType.GuildMedia,
|
||||||
|
];
|
||||||
|
|
||||||
const VoiceSortableGroupTypes = [ChannelType.GuildVoice, ChannelType.GuildStageVoice];
|
const VoiceSortableGroupTypes = [ChannelType.GuildVoice, ChannelType.GuildStageVoice];
|
||||||
const CategorySortableGroupTypes = [ChannelType.GuildCategory];
|
const CategorySortableGroupTypes = [ChannelType.GuildCategory];
|
||||||
|
|
||||||
@@ -181,6 +187,7 @@ function getSortableGroupTypes(type) {
|
|||||||
case ChannelType.GuildText:
|
case ChannelType.GuildText:
|
||||||
case ChannelType.GuildAnnouncement:
|
case ChannelType.GuildAnnouncement:
|
||||||
case ChannelType.GuildForum:
|
case ChannelType.GuildForum:
|
||||||
|
case ChannelType.GuildMedia:
|
||||||
return TextSortableGroupTypes;
|
return TextSortableGroupTypes;
|
||||||
case ChannelType.GuildVoice:
|
case ChannelType.GuildVoice:
|
||||||
case ChannelType.GuildStageVoice:
|
case ChannelType.GuildStageVoice:
|
||||||
|
|||||||
59
packages/discord.js/typings/index.d.ts
vendored
59
packages/discord.js/typings/index.d.ts
vendored
@@ -357,7 +357,7 @@ export class AutoModerationActionExecution {
|
|||||||
public ruleTriggerType: AutoModerationRuleTriggerType;
|
public ruleTriggerType: AutoModerationRuleTriggerType;
|
||||||
public get user(): User | null;
|
public get user(): User | null;
|
||||||
public userId: Snowflake;
|
public userId: Snowflake;
|
||||||
public get channel(): GuildTextBasedChannel | ForumChannel | null;
|
public get channel(): GuildTextBasedChannel | ForumChannel | MediaChannel | null;
|
||||||
public channelId: Snowflake | null;
|
public channelId: Snowflake | null;
|
||||||
public get member(): GuildMember | null;
|
public get member(): GuildMember | null;
|
||||||
public messageId: Snowflake | null;
|
public messageId: Snowflake | null;
|
||||||
@@ -894,6 +894,7 @@ export interface MappedChannelCategoryTypes {
|
|||||||
[ChannelType.GuildText]: TextChannel;
|
[ChannelType.GuildText]: TextChannel;
|
||||||
[ChannelType.GuildStageVoice]: StageChannel;
|
[ChannelType.GuildStageVoice]: StageChannel;
|
||||||
[ChannelType.GuildForum]: ForumChannel;
|
[ChannelType.GuildForum]: ForumChannel;
|
||||||
|
[ChannelType.GuildMedia]: MediaChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CategoryChannelType = Exclude<
|
export type CategoryChannelType = Exclude<
|
||||||
@@ -905,8 +906,6 @@ export type CategoryChannelType = Exclude<
|
|||||||
| ChannelType.PrivateThread
|
| ChannelType.PrivateThread
|
||||||
| ChannelType.GuildCategory
|
| ChannelType.GuildCategory
|
||||||
| ChannelType.GuildDirectory
|
| ChannelType.GuildDirectory
|
||||||
// TODO: https://github.com/discordjs/discord.js/pull/9662
|
|
||||||
| ChannelType.GuildMedia
|
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export class CategoryChannel extends GuildChannel {
|
export class CategoryChannel extends GuildChannel {
|
||||||
@@ -1364,7 +1363,7 @@ export class Guild extends AnonymousGuild {
|
|||||||
public vanityURLUses: number | null;
|
public vanityURLUses: number | null;
|
||||||
public get voiceAdapterCreator(): InternalDiscordGatewayAdapterCreator;
|
public get voiceAdapterCreator(): InternalDiscordGatewayAdapterCreator;
|
||||||
public voiceStates: VoiceStateManager;
|
public voiceStates: VoiceStateManager;
|
||||||
public get widgetChannel(): TextChannel | NewsChannel | VoiceBasedChannel | ForumChannel | null;
|
public get widgetChannel(): TextChannel | NewsChannel | VoiceBasedChannel | ForumChannel | MediaChannel | null;
|
||||||
public widgetChannelId: Snowflake | null;
|
public widgetChannelId: Snowflake | null;
|
||||||
public widgetEnabled: boolean | null;
|
public widgetEnabled: boolean | null;
|
||||||
public get maximumBitrate(): number;
|
public get maximumBitrate(): number;
|
||||||
@@ -2394,7 +2393,7 @@ export interface DefaultReactionEmoji {
|
|||||||
name: string | null;
|
name: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ForumChannel extends TextBasedChannelMixin(GuildChannel, true, [
|
export abstract class ThreadOnlyChannel extends TextBasedChannelMixin(GuildChannel, true, [
|
||||||
'send',
|
'send',
|
||||||
'lastMessage',
|
'lastMessage',
|
||||||
'lastPinAt',
|
'lastPinAt',
|
||||||
@@ -2405,7 +2404,7 @@ export class ForumChannel extends TextBasedChannelMixin(GuildChannel, true, [
|
|||||||
'createMessageComponentCollector',
|
'createMessageComponentCollector',
|
||||||
'awaitMessageComponent',
|
'awaitMessageComponent',
|
||||||
]) {
|
]) {
|
||||||
public type: ChannelType.GuildForum;
|
public type: ChannelType.GuildForum | ChannelType.GuildMedia;
|
||||||
public threads: GuildForumThreadManager;
|
public threads: GuildForumThreadManager;
|
||||||
public availableTags: GuildForumTag[];
|
public availableTags: GuildForumTag[];
|
||||||
public defaultReactionEmoji: DefaultReactionEmoji | null;
|
public defaultReactionEmoji: DefaultReactionEmoji | null;
|
||||||
@@ -2415,8 +2414,6 @@ export class ForumChannel extends TextBasedChannelMixin(GuildChannel, true, [
|
|||||||
public nsfw: boolean;
|
public nsfw: boolean;
|
||||||
public topic: string | null;
|
public topic: string | null;
|
||||||
public defaultSortOrder: SortOrderType | null;
|
public defaultSortOrder: SortOrderType | null;
|
||||||
public defaultForumLayout: ForumLayoutType;
|
|
||||||
|
|
||||||
public setAvailableTags(tags: GuildForumTagData[], reason?: string): Promise<this>;
|
public setAvailableTags(tags: GuildForumTagData[], reason?: string): Promise<this>;
|
||||||
public setDefaultReactionEmoji(emojiId: DefaultReactionEmoji | null, reason?: string): Promise<this>;
|
public setDefaultReactionEmoji(emojiId: DefaultReactionEmoji | null, reason?: string): Promise<this>;
|
||||||
public setDefaultThreadRateLimitPerUser(rateLimit: number, reason?: string): Promise<this>;
|
public setDefaultThreadRateLimitPerUser(rateLimit: number, reason?: string): Promise<this>;
|
||||||
@@ -2428,9 +2425,18 @@ export class ForumChannel extends TextBasedChannelMixin(GuildChannel, true, [
|
|||||||
): Promise<this>;
|
): Promise<this>;
|
||||||
public setTopic(topic: string | null, reason?: string): Promise<this>;
|
public setTopic(topic: string | null, reason?: string): Promise<this>;
|
||||||
public setDefaultSortOrder(defaultSortOrder: SortOrderType | null, reason?: string): Promise<this>;
|
public setDefaultSortOrder(defaultSortOrder: SortOrderType | null, reason?: string): Promise<this>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ForumChannel extends ThreadOnlyChannel {
|
||||||
|
public type: ChannelType.GuildForum;
|
||||||
|
public defaultForumLayout: ForumLayoutType;
|
||||||
public setDefaultForumLayout(defaultForumLayout: ForumLayoutType, reason?: string): Promise<this>;
|
public setDefaultForumLayout(defaultForumLayout: ForumLayoutType, reason?: string): Promise<this>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class MediaChannel extends ThreadOnlyChannel {
|
||||||
|
public type: ChannelType.GuildMedia;
|
||||||
|
}
|
||||||
|
|
||||||
export class PermissionOverwrites extends Base {
|
export class PermissionOverwrites extends Base {
|
||||||
private constructor(client: Client<true>, data: RawPermissionOverwriteData, channel: NonThreadGuildBasedChannel);
|
private constructor(client: Client<true>, data: RawPermissionOverwriteData, channel: NonThreadGuildBasedChannel);
|
||||||
public allow: Readonly<PermissionsBitField>;
|
public allow: Readonly<PermissionsBitField>;
|
||||||
@@ -3025,7 +3031,7 @@ export interface PrivateThreadChannel extends ThreadChannel<false> {
|
|||||||
type: ChannelType.PrivateThread;
|
type: ChannelType.PrivateThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ThreadChannel<Forum extends boolean = boolean> extends TextBasedChannelMixin(BaseChannel, true, [
|
export class ThreadChannel<ThreadOnly extends boolean = boolean> extends TextBasedChannelMixin(BaseChannel, true, [
|
||||||
'fetchWebhooks',
|
'fetchWebhooks',
|
||||||
'createWebhook',
|
'createWebhook',
|
||||||
'setNSFW',
|
'setNSFW',
|
||||||
@@ -3057,7 +3063,7 @@ export class ThreadChannel<Forum extends boolean = boolean> extends TextBasedCha
|
|||||||
public members: ThreadMemberManager;
|
public members: ThreadMemberManager;
|
||||||
public name: string;
|
public name: string;
|
||||||
public ownerId: Snowflake | null;
|
public ownerId: Snowflake | null;
|
||||||
public get parent(): If<Forum, ForumChannel, TextChannel | NewsChannel> | null;
|
public get parent(): If<ThreadOnly, ForumChannel | MediaChannel, TextChannel | NewsChannel> | null;
|
||||||
public parentId: Snowflake | null;
|
public parentId: Snowflake | null;
|
||||||
public rateLimitPerUser: number | null;
|
public rateLimitPerUser: number | null;
|
||||||
public type: ThreadChannelType;
|
public type: ThreadChannelType;
|
||||||
@@ -3343,7 +3349,7 @@ export class Webhook extends WebhookMixin() {
|
|||||||
public token: string | null;
|
public token: string | null;
|
||||||
public type: WebhookType;
|
public type: WebhookType;
|
||||||
public applicationId: Snowflake | null;
|
public applicationId: Snowflake | null;
|
||||||
public get channel(): TextChannel | VoiceChannel | NewsChannel | ForumChannel | StageChannel | null;
|
public get channel(): TextChannel | VoiceChannel | NewsChannel | StageChannel | ForumChannel | MediaChannel | null;
|
||||||
public isUserCreated(): this is this & {
|
public isUserCreated(): this is this & {
|
||||||
type: WebhookType.Incoming;
|
type: WebhookType.Incoming;
|
||||||
applicationId: null;
|
applicationId: null;
|
||||||
@@ -3488,7 +3494,7 @@ export class WelcomeChannel extends Base {
|
|||||||
public channelId: Snowflake;
|
public channelId: Snowflake;
|
||||||
public guild: Guild | InviteGuild;
|
public guild: Guild | InviteGuild;
|
||||||
public description: string;
|
public description: string;
|
||||||
public get channel(): TextChannel | NewsChannel | ForumChannel | null;
|
public get channel(): TextChannel | NewsChannel | ForumChannel | MediaChannel | null;
|
||||||
public get emoji(): GuildEmoji | Emoji;
|
public get emoji(): GuildEmoji | Emoji;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4200,13 +4206,16 @@ export class StageInstanceManager extends CachedManager<Snowflake, StageInstance
|
|||||||
public delete(channel: StageChannelResolvable): Promise<void>;
|
public delete(channel: StageChannelResolvable): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ThreadManager<Forum extends boolean = boolean> extends CachedManager<
|
export class ThreadManager<ThreadOnly extends boolean = boolean> extends CachedManager<
|
||||||
Snowflake,
|
Snowflake,
|
||||||
ThreadChannel<Forum>,
|
ThreadChannel<ThreadOnly>,
|
||||||
ThreadChannelResolvable
|
ThreadChannelResolvable
|
||||||
> {
|
> {
|
||||||
protected constructor(channel: TextChannel | NewsChannel | ForumChannel, iterable?: Iterable<RawThreadChannelData>);
|
protected constructor(
|
||||||
public channel: If<Forum, ForumChannel, TextChannel | NewsChannel>;
|
channel: TextChannel | NewsChannel | ForumChannel | MediaChannel,
|
||||||
|
iterable?: Iterable<RawThreadChannelData>,
|
||||||
|
);
|
||||||
|
public channel: If<ThreadOnly, ForumChannel | MediaChannel, TextChannel | NewsChannel>;
|
||||||
public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<AnyThreadChannel | null>;
|
public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<AnyThreadChannel | null>;
|
||||||
public fetch(
|
public fetch(
|
||||||
options: FetchThreadsOptions & { archived: FetchArchivedThreadOptions },
|
options: FetchThreadsOptions & { archived: FetchArchivedThreadOptions },
|
||||||
@@ -4847,7 +4856,7 @@ export interface ChannelWebhookCreateOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface WebhookCreateOptions extends ChannelWebhookCreateOptions {
|
export interface WebhookCreateOptions extends ChannelWebhookCreateOptions {
|
||||||
channel: TextChannel | NewsChannel | VoiceChannel | StageChannel | ForumChannel | Snowflake;
|
channel: TextChannel | NewsChannel | VoiceChannel | StageChannel | ForumChannel | MediaChannel | Snowflake;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClientEvents {
|
export interface ClientEvents {
|
||||||
@@ -4925,7 +4934,7 @@ export interface ClientEvents {
|
|||||||
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
|
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
|
||||||
/** @deprecated Use {@link webhooksUpdate} instead. */
|
/** @deprecated Use {@link webhooksUpdate} instead. */
|
||||||
webhookUpdate: ClientEvents['webhooksUpdate'];
|
webhookUpdate: ClientEvents['webhooksUpdate'];
|
||||||
webhooksUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel];
|
webhooksUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel | MediaChannel];
|
||||||
interactionCreate: [interaction: Interaction];
|
interactionCreate: [interaction: Interaction];
|
||||||
shardDisconnect: [closeEvent: CloseEvent, shardId: number];
|
shardDisconnect: [closeEvent: CloseEvent, shardId: number];
|
||||||
shardError: [error: Error, shardId: number];
|
shardError: [error: Error, shardId: number];
|
||||||
@@ -5610,7 +5619,7 @@ export interface GuildCreateOptions {
|
|||||||
|
|
||||||
export interface GuildWidgetSettings {
|
export interface GuildWidgetSettings {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
channel: TextChannel | NewsChannel | VoiceBasedChannel | ForumChannel | null;
|
channel: TextChannel | NewsChannel | VoiceBasedChannel | ForumChannel | MediaChannel | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GuildEditOptions {
|
export interface GuildEditOptions {
|
||||||
@@ -5690,7 +5699,7 @@ export interface GuildPruneMembersOptions {
|
|||||||
|
|
||||||
export interface GuildWidgetSettingsData {
|
export interface GuildWidgetSettingsData {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
channel: TextChannel | NewsChannel | VoiceBasedChannel | ForumChannel | Snowflake | null;
|
channel: TextChannel | NewsChannel | VoiceBasedChannel | ForumChannel | MediaChannel | Snowflake | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GuildSearchMembersOptions {
|
export interface GuildSearchMembersOptions {
|
||||||
@@ -5836,6 +5845,7 @@ export type GuildInvitableChannelResolvable =
|
|||||||
| NewsChannel
|
| NewsChannel
|
||||||
| StageChannel
|
| StageChannel
|
||||||
| ForumChannel
|
| ForumChannel
|
||||||
|
| MediaChannel
|
||||||
| Snowflake;
|
| Snowflake;
|
||||||
|
|
||||||
export interface InviteCreateOptions {
|
export interface InviteCreateOptions {
|
||||||
@@ -6354,11 +6364,12 @@ export type Channel =
|
|||||||
| TextChannel
|
| TextChannel
|
||||||
| AnyThreadChannel
|
| AnyThreadChannel
|
||||||
| VoiceChannel
|
| VoiceChannel
|
||||||
| ForumChannel;
|
| ForumChannel
|
||||||
|
| MediaChannel;
|
||||||
|
|
||||||
export type TextBasedChannel = Exclude<
|
export type TextBasedChannel = Exclude<
|
||||||
Extract<Channel, { type: TextChannelType }>,
|
Extract<Channel, { type: TextChannelType }>,
|
||||||
PartialGroupDMChannel | ForumChannel
|
PartialGroupDMChannel | ForumChannel | MediaChannel
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export type TextBasedChannelTypes = TextBasedChannel['type'];
|
export type TextBasedChannelTypes = TextBasedChannel['type'];
|
||||||
@@ -6447,7 +6458,7 @@ export interface WebhookDeleteOptions {
|
|||||||
export interface WebhookEditOptions {
|
export interface WebhookEditOptions {
|
||||||
name?: string;
|
name?: string;
|
||||||
avatar?: BufferResolvable | null;
|
avatar?: BufferResolvable | null;
|
||||||
channel?: GuildTextChannelResolvable | VoiceChannel | ForumChannel | StageChannel;
|
channel?: GuildTextChannelResolvable | VoiceChannel | StageChannel | ForumChannel | MediaChannel;
|
||||||
reason?: string;
|
reason?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6489,7 +6500,7 @@ export interface WidgetChannel {
|
|||||||
|
|
||||||
export interface WelcomeChannelData {
|
export interface WelcomeChannelData {
|
||||||
description: string;
|
description: string;
|
||||||
channel: TextChannel | NewsChannel | ForumChannel | Snowflake;
|
channel: TextChannel | NewsChannel | ForumChannel | MediaChannel | Snowflake;
|
||||||
emoji?: EmojiIdentifierResolvable;
|
emoji?: EmojiIdentifierResolvable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ import {
|
|||||||
GuildOnboarding,
|
GuildOnboarding,
|
||||||
StringSelectMenuComponentData,
|
StringSelectMenuComponentData,
|
||||||
ButtonComponentData,
|
ButtonComponentData,
|
||||||
|
MediaChannel,
|
||||||
} from '.';
|
} from '.';
|
||||||
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
|
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
|
||||||
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
|
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
|
||||||
@@ -1324,8 +1325,8 @@ declare const user: User;
|
|||||||
declare const guildMember: GuildMember;
|
declare const guildMember: GuildMember;
|
||||||
|
|
||||||
// Test thread channels' parent inference
|
// Test thread channels' parent inference
|
||||||
expectType<TextChannel | NewsChannel | ForumChannel | null>(threadChannel.parent);
|
expectType<TextChannel | NewsChannel | ForumChannel | MediaChannel | null>(threadChannel.parent);
|
||||||
expectType<ForumChannel | null>(threadChannelFromForum.parent);
|
expectType<ForumChannel | MediaChannel | null>(threadChannelFromForum.parent);
|
||||||
expectType<TextChannel | NewsChannel | null>(threadChannelNotFromForum.parent);
|
expectType<TextChannel | NewsChannel | null>(threadChannelNotFromForum.parent);
|
||||||
|
|
||||||
// Test whether the structures implement send
|
// Test whether the structures implement send
|
||||||
@@ -1544,6 +1545,7 @@ declare const guildChannelManager: GuildChannelManager;
|
|||||||
expectType<Promise<NewsChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildAnnouncement }));
|
expectType<Promise<NewsChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildAnnouncement }));
|
||||||
expectType<Promise<StageChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildStageVoice }));
|
expectType<Promise<StageChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildStageVoice }));
|
||||||
expectType<Promise<ForumChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildForum }));
|
expectType<Promise<ForumChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildForum }));
|
||||||
|
expectType<Promise<MediaChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildMedia }));
|
||||||
|
|
||||||
expectType<Promise<Collection<Snowflake, NonThreadGuildBasedChannel | null>>>(guildChannelManager.fetch());
|
expectType<Promise<Collection<Snowflake, NonThreadGuildBasedChannel | null>>>(guildChannelManager.fetch());
|
||||||
expectType<Promise<Collection<Snowflake, NonThreadGuildBasedChannel | null>>>(
|
expectType<Promise<Collection<Snowflake, NonThreadGuildBasedChannel | null>>>(
|
||||||
@@ -1603,7 +1605,7 @@ declare const threadManager: ThreadManager;
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare const guildForumThreadManager: GuildForumThreadManager;
|
declare const guildForumThreadManager: GuildForumThreadManager;
|
||||||
expectType<ForumChannel>(guildForumThreadManager.channel);
|
expectType<ForumChannel | MediaChannel>(guildForumThreadManager.channel);
|
||||||
|
|
||||||
declare const guildTextThreadManager: GuildTextThreadManager<
|
declare const guildTextThreadManager: GuildTextThreadManager<
|
||||||
ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread
|
ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread
|
||||||
@@ -1926,6 +1928,7 @@ client.on('interactionCreate', async interaction => {
|
|||||||
expectType<ForumChannel | VoiceChannel | null>(
|
expectType<ForumChannel | VoiceChannel | null>(
|
||||||
interaction.options.getChannel('test', false, [ChannelType.GuildForum, ChannelType.GuildVoice]),
|
interaction.options.getChannel('test', false, [ChannelType.GuildForum, ChannelType.GuildVoice]),
|
||||||
);
|
);
|
||||||
|
expectType<MediaChannel>(interaction.options.getChannel('test', true, [ChannelType.GuildMedia]));
|
||||||
} else {
|
} else {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
consumeCachedCommand(interaction);
|
consumeCachedCommand(interaction);
|
||||||
@@ -2117,7 +2120,7 @@ expectType<
|
|||||||
>(TextBasedChannelTypes);
|
>(TextBasedChannelTypes);
|
||||||
expectType<StageChannel | VoiceChannel>(VoiceBasedChannel);
|
expectType<StageChannel | VoiceChannel>(VoiceBasedChannel);
|
||||||
expectType<GuildBasedChannel>(GuildBasedChannel);
|
expectType<GuildBasedChannel>(GuildBasedChannel);
|
||||||
expectType<CategoryChannel | NewsChannel | StageChannel | TextChannel | VoiceChannel | ForumChannel>(
|
expectType<CategoryChannel | NewsChannel | StageChannel | TextChannel | VoiceChannel | ForumChannel | MediaChannel>(
|
||||||
NonThreadGuildBasedChannel,
|
NonThreadGuildBasedChannel,
|
||||||
);
|
);
|
||||||
expectType<GuildTextBasedChannel>(GuildTextBasedChannel);
|
expectType<GuildTextBasedChannel>(GuildTextBasedChannel);
|
||||||
|
|||||||
Reference in New Issue
Block a user