Skip to content

Commit 571aedd

Browse files
JiraliteSpaceEECkodiakhq[bot]
authored
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 <[email protected]> --------- Co-authored-by: space <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent e02a59b commit 571aedd

File tree

19 files changed

+342
-281
lines changed

19 files changed

+342
-281
lines changed

packages/builders/src/interactions/slashCommands/mixins/ApplicationCommandOptionChannelTypesMixin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const allowedChannelTypes = [
1717
ChannelType.PrivateThread,
1818
ChannelType.GuildStageVoice,
1919
ChannelType.GuildForum,
20+
ChannelType.GuildMedia,
2021
] as const;
2122

2223
/**

packages/discord.js/src/client/actions/WebhooksUpdate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class WebhooksUpdate extends Action {
1515
/**
1616
* Emitted whenever a channel has its webhooks changed.
1717
* @event Client#webhooksUpdate
18-
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel
18+
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel} channel
1919
* The channel that had a webhook update
2020
*/
2121
client.emit('webhooksUpdate', channel);
2222

2323
/**
2424
* Emitted whenever a channel has its webhooks changed.
2525
* @event Client#webhookUpdate
26-
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel} channel
26+
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel} channel
2727
* The channel that had a webhook update
2828
* @deprecated Use {@link Client#event:webhooksUpdate} instead.
2929
*/

packages/discord.js/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ exports.Message = require('./structures/Message').Message;
149149
exports.Attachment = require('./structures/Attachment');
150150
exports.AttachmentBuilder = require('./structures/AttachmentBuilder');
151151
exports.ModalBuilder = require('./structures/ModalBuilder');
152+
exports.MediaChannel = require('./structures/MediaChannel');
152153
exports.MessageCollector = require('./structures/MessageCollector');
153154
exports.MessageComponentInteraction = require('./structures/MessageComponentInteraction');
154155
exports.MessageContextMenuCommandInteraction = require('./structures/MessageContextMenuCommandInteraction');
@@ -199,6 +200,7 @@ exports.TextInputBuilder = require('./structures/TextInputBuilder');
199200
exports.TextInputComponent = require('./structures/TextInputComponent');
200201
exports.ThreadChannel = require('./structures/ThreadChannel');
201202
exports.ThreadMember = require('./structures/ThreadMember');
203+
exports.ThreadOnlyChannel = require('./structures/ThreadOnlyChannel');
202204
exports.Typing = require('./structures/Typing');
203205
exports.User = require('./structures/User');
204206
exports.UserContextMenuCommandInteraction = require('./structures/UserContextMenuCommandInteraction');

packages/discord.js/src/managers/GuildChannelManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class GuildChannelManager extends CachedManager {
194194

195195
/**
196196
* @typedef {ChannelWebhookCreateOptions} WebhookCreateOptions
197-
* @property {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|Snowflake} channel
197+
* @property {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel|Snowflake} channel
198198
* The channel to create the webhook for
199199
*/
200200

packages/discord.js/src/managers/GuildInviteManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ class GuildInviteManager extends CachedManager {
4646
* * NewsChannel
4747
* * StageChannel
4848
* * ForumChannel
49+
* * MediaChannel
4950
* * Snowflake
50-
* @typedef {TextChannel|VoiceChannel|NewsChannel|StageChannel|ForumChannel|Snowflake}
51+
* @typedef {TextChannel|VoiceChannel|NewsChannel|StageChannel|ForumChannel|MediaChannel|Snowflake}
5152
* GuildInvitableChannelResolvable
5253
*/
5354

packages/discord.js/src/managers/ThreadManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ThreadManager extends CachedManager {
2020

2121
/**
2222
* The channel this Manager belongs to
23-
* @type {TextChannel|NewsChannel|ForumChannel}
23+
* @type {TextChannel|NewsChannel|ForumChannel|MediaChannel}
2424
*/
2525
this.channel = channel;
2626
}

packages/discord.js/src/structures/AutoModerationActionExecution.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class AutoModerationActionExecution {
8787

8888
/**
8989
* The channel where this action was triggered from.
90-
* @type {?(GuildTextBasedChannel|ForumChannel)}
90+
* @type {?(GuildTextBasedChannel|ForumChannel|MediaChannel)}
9191
* @readonly
9292
*/
9393
get channel() {
Lines changed: 4 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,14 @@
11
'use strict';
22

3-
const GuildChannel = require('./GuildChannel');
4-
const TextBasedChannel = require('./interfaces/TextBasedChannel');
5-
const GuildForumThreadManager = require('../managers/GuildForumThreadManager');
6-
const { transformAPIGuildForumTag, transformAPIGuildDefaultReaction } = require('../util/Channels');
3+
const ThreadOnlyChannel = require('./ThreadOnlyChannel');
74

85
/**
9-
* @typedef {Object} GuildForumTagEmoji
10-
* @property {?Snowflake} id The id of a guild's custom emoji
11-
* @property {?string} name The unicode character of the emoji
6+
* Represents a forum channel.
7+
* @extends {ThreadOnlyChannel}
128
*/
13-
14-
/**
15-
* @typedef {Object} GuildForumTag
16-
* @property {Snowflake} id The id of the tag
17-
* @property {string} name The name of the tag
18-
* @property {boolean} moderated Whether this tag can only be added to or removed from threads
19-
* by a member with the `ManageThreads` permission
20-
* @property {?GuildForumTagEmoji} emoji The emoji of this tag
21-
*/
22-
23-
/**
24-
* @typedef {Object} GuildForumTagData
25-
* @property {Snowflake} [id] The id of the tag
26-
* @property {string} name The name of the tag
27-
* @property {boolean} [moderated] Whether this tag can only be added to or removed from threads
28-
* by a member with the `ManageThreads` permission
29-
* @property {?GuildForumTagEmoji} [emoji] The emoji of this tag
30-
*/
31-
32-
/**
33-
* @typedef {Object} DefaultReactionEmoji
34-
* @property {?Snowflake} id The id of a guild's custom emoji
35-
* @property {?string} name The unicode character of the emoji
36-
*/
37-
38-
/**
39-
* Represents a channel that only contains threads
40-
* @extends {GuildChannel}
41-
* @implements {TextBasedChannel}
42-
*/
43-
class ForumChannel extends GuildChannel {
44-
constructor(guild, data, client) {
45-
super(guild, data, client, false);
46-
47-
/**
48-
* A manager of the threads belonging to this channel
49-
* @type {GuildForumThreadManager}
50-
*/
51-
this.threads = new GuildForumThreadManager(this);
52-
53-
this._patch(data);
54-
}
55-
9+
class ForumChannel extends ThreadOnlyChannel {
5610
_patch(data) {
5711
super._patch(data);
58-
if ('available_tags' in data) {
59-
/**
60-
* The set of tags that can be used in this channel.
61-
* @type {GuildForumTag[]}
62-
*/
63-
this.availableTags = data.available_tags.map(tag => transformAPIGuildForumTag(tag));
64-
} else {
65-
this.availableTags ??= [];
66-
}
67-
68-
if ('default_reaction_emoji' in data) {
69-
/**
70-
* The emoji to show in the add reaction button on a thread in a guild forum channel
71-
* @type {?DefaultReactionEmoji}
72-
*/
73-
this.defaultReactionEmoji = data.default_reaction_emoji
74-
? transformAPIGuildDefaultReaction(data.default_reaction_emoji)
75-
: null;
76-
} else {
77-
this.defaultReactionEmoji ??= null;
78-
}
79-
80-
if ('default_thread_rate_limit_per_user' in data) {
81-
/**
82-
* The initial rate limit per user (slowmode) to set on newly created threads in a channel.
83-
* @type {?number}
84-
*/
85-
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user;
86-
} else {
87-
this.defaultThreadRateLimitPerUser ??= null;
88-
}
89-
90-
if ('rate_limit_per_user' in data) {
91-
/**
92-
* The rate limit per user (slowmode) for this channel.
93-
* @type {?number}
94-
*/
95-
this.rateLimitPerUser = data.rate_limit_per_user;
96-
} else {
97-
this.rateLimitPerUser ??= null;
98-
}
99-
100-
if ('default_auto_archive_duration' in data) {
101-
/**
102-
* The default auto archive duration for newly created threads in this channel.
103-
* @type {?ThreadAutoArchiveDuration}
104-
*/
105-
this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
106-
} else {
107-
this.defaultAutoArchiveDuration ??= null;
108-
}
109-
110-
if ('nsfw' in data) {
111-
/**
112-
* If this channel is considered NSFW.
113-
* @type {boolean}
114-
*/
115-
this.nsfw = data.nsfw;
116-
} else {
117-
this.nsfw ??= false;
118-
}
119-
120-
if ('topic' in data) {
121-
/**
122-
* The topic of this channel.
123-
* @type {?string}
124-
*/
125-
this.topic = data.topic;
126-
}
127-
128-
if ('default_sort_order' in data) {
129-
/**
130-
* The default sort order mode used to order posts
131-
* @type {?SortOrderType}
132-
*/
133-
this.defaultSortOrder = data.default_sort_order;
134-
} else {
135-
this.defaultSortOrder ??= null;
136-
}
13712

13813
/**
13914
* The default layout type used to display posts
@@ -142,95 +17,6 @@ class ForumChannel extends GuildChannel {
14217
this.defaultForumLayout = data.default_forum_layout;
14318
}
14419

145-
/**
146-
* Sets the available tags for this forum channel
147-
* @param {GuildForumTagData[]} availableTags The tags to set as available in this channel
148-
* @param {string} [reason] Reason for changing the available tags
149-
* @returns {Promise<ForumChannel>}
150-
*/
151-
setAvailableTags(availableTags, reason) {
152-
return this.edit({ availableTags, reason });
153-
}
154-
155-
/**
156-
* Sets the default reaction emoji for this channel
157-
* @param {?DefaultReactionEmoji} defaultReactionEmoji The emoji to set as the default reaction emoji
158-
* @param {string} [reason] Reason for changing the default reaction emoji
159-
* @returns {Promise<ForumChannel>}
160-
*/
161-
setDefaultReactionEmoji(defaultReactionEmoji, reason) {
162-
return this.edit({ defaultReactionEmoji, reason });
163-
}
164-
165-
/**
166-
* Sets the default rate limit per user (slowmode) for new threads in this channel
167-
* @param {number} defaultThreadRateLimitPerUser The rate limit to set on newly created threads in this channel
168-
* @param {string} [reason] Reason for changing the default rate limit
169-
* @returns {Promise<ForumChannel>}
170-
*/
171-
setDefaultThreadRateLimitPerUser(defaultThreadRateLimitPerUser, reason) {
172-
return this.edit({ defaultThreadRateLimitPerUser, reason });
173-
}
174-
175-
/**
176-
* Creates an invite to this guild channel.
177-
* @param {InviteCreateOptions} [options={}] The options for creating the invite
178-
* @returns {Promise<Invite>}
179-
* @example
180-
* // Create an invite to a channel
181-
* channel.createInvite()
182-
* .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
183-
* .catch(console.error);
184-
*/
185-
createInvite(options) {
186-
return this.guild.invites.create(this.id, options);
187-
}
188-
189-
/**
190-
* Fetches a collection of invites to this guild channel.
191-
* Resolves with a collection mapping invites by their codes.
192-
* @param {boolean} [cache=true] Whether to cache the fetched invites
193-
* @returns {Promise<Collection<string, Invite>>}
194-
*/
195-
fetchInvites(cache) {
196-
return this.guild.invites.fetch({ channelId: this.id, cache });
197-
}
198-
199-
/**
200-
* Sets the default auto archive duration for all newly created threads in this channel.
201-
* @param {ThreadAutoArchiveDuration} defaultAutoArchiveDuration The new default auto archive duration
202-
* @param {string} [reason] Reason for changing the channel's default auto archive duration
203-
* @returns {Promise<ForumChannel>}
204-
*/
205-
setDefaultAutoArchiveDuration(defaultAutoArchiveDuration, reason) {
206-
return this.edit({ defaultAutoArchiveDuration, reason });
207-
}
208-
209-
/**
210-
* Sets a new topic for the guild channel.
211-
* @param {?string} topic The new topic for the guild channel
212-
* @param {string} [reason] Reason for changing the guild channel's topic
213-
* @returns {Promise<ForumChannel>}
214-
* @example
215-
* // Set a new channel topic
216-
* channel.setTopic('needs more rate limiting')
217-
* .then(newChannel => console.log(`Channel's new topic is ${newChannel.topic}`))
218-
* .catch(console.error);
219-
*/
220-
setTopic(topic, reason) {
221-
return this.edit({ topic, reason });
222-
}
223-
224-
/**
225-
* Sets the default sort order mode used to order posts
226-
* @param {?SortOrderType} defaultSortOrder The default sort order mode to set on this channel
227-
* @param {string} [reason] Reason for changing the default sort order
228-
* @returns {Promise<ForumChannel>}
229-
*/
230-
setDefaultSortOrder(defaultSortOrder, reason) {
231-
return this.edit({ defaultSortOrder, reason });
232-
}
233-
23420
/**
23521
* Sets the default forum layout type used to display posts
23622
* @param {ForumLayoutType} defaultForumLayout The default forum layout type to set on this channel
@@ -240,25 +26,6 @@ class ForumChannel extends GuildChannel {
24026
setDefaultForumLayout(defaultForumLayout, reason) {
24127
return this.edit({ defaultForumLayout, reason });
24228
}
243-
244-
// These are here only for documentation purposes - they are implemented by TextBasedChannel
245-
/* eslint-disable no-empty-function */
246-
createWebhook() {}
247-
fetchWebhooks() {}
248-
setNSFW() {}
249-
setRateLimitPerUser() {}
25029
}
25130

252-
TextBasedChannel.applyToClass(ForumChannel, true, [
253-
'send',
254-
'lastMessage',
255-
'lastPinAt',
256-
'bulkDelete',
257-
'sendTyping',
258-
'createMessageCollector',
259-
'awaitMessages',
260-
'createMessageComponentCollector',
261-
'awaitMessageComponent',
262-
]);
263-
26431
module.exports = ForumChannel;

packages/discord.js/src/structures/Guild.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ class Guild extends AnonymousGuild {
520520

521521
/**
522522
* Widget channel for this guild
523-
* @type {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel)}
523+
* @type {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel)}
524524
* @readonly
525525
*/
526526
get widgetChannel() {
@@ -693,14 +693,15 @@ class Guild extends AnonymousGuild {
693693
* Data for the Guild Widget Settings object
694694
* @typedef {Object} GuildWidgetSettings
695695
* @property {boolean} enabled Whether the widget is enabled
696-
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel)} channel The widget invite channel
696+
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel)} channel
697+
* The widget invite channel
697698
*/
698699

699700
/**
700701
* The Guild Widget Settings object
701702
* @typedef {Object} GuildWidgetSettingsData
702703
* @property {boolean} enabled Whether the widget is enabled
703-
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|Snowflake)} channel
704+
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel|Snowflake)} channel
704705
* The widget invite channel
705706
*/
706707

@@ -884,7 +885,8 @@ class Guild extends AnonymousGuild {
884885
* Welcome channel data
885886
* @typedef {Object} WelcomeChannelData
886887
* @property {string} description The description to show for this welcome channel
887-
* @property {TextChannel|NewsChannel|ForumChannel|Snowflake} channel The channel to link for this welcome channel
888+
* @property {TextChannel|NewsChannel|ForumChannel|MediaChannel|Snowflake} channel
889+
* The channel to link for this welcome channel
888890
* @property {EmojiIdentifierResolvable} [emoji] The emoji to display for this welcome channel
889891
*/
890892

packages/discord.js/src/structures/GuildChannel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const { getSortableGroupTypes } = require('../util/Util');
1717
* - {@link NewsChannel}
1818
* - {@link StageChannel}
1919
* - {@link ForumChannel}
20+
* - {@link MediaChannel}
2021
* @extends {BaseChannel}
2122
* @abstract
2223
*/

0 commit comments

Comments
 (0)