Skip to content

Commit

Permalink
refactor(NewsChannel)!: rename NewsChannel to AnnouncementChannel (#1…
Browse files Browse the repository at this point in the history
…0532)

BREAKING CHANGE: The `NewsChannel` class was renamed to `AnnouncementChannel`, in line with the type name change
  • Loading branch information
imnaiyar authored Oct 9, 2024
1 parent a65c762 commit c8ef899
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 79 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/client/actions/ThreadListSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ThreadListSyncAction extends Action {
}

/**
* Emitted whenever the client user gains access to a text or news channel that contains threads
* Emitted whenever the client user gains access to a text or announcement channel that contains threads
* @event Client#threadListSync
* @param {Collection<Snowflake, ThreadChannel>} threads The threads that were synced
* @param {Guild} guild The guild that the threads were synced in
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/client/actions/WebhooksUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class WebhooksUpdate extends Action {
/**
* Emitted whenever a channel has its webhooks changed.
* @event Client#webhooksUpdate
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel} channel
* @param {TextChannel|AnnouncementChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel} channel
* The channel that had a webhook update
*/
client.emit(Events.WebhooksUpdate, channel);
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/errors/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const Messages = {
[DjsErrorCodes.InvalidType]: (name, expected, an = false) => `Supplied ${name} is not a${an ? 'n' : ''} ${expected}.`,
[DjsErrorCodes.InvalidElement]: (type, name, elem) => `Supplied ${type} ${name} includes an invalid element: ${elem}`,

[DjsErrorCodes.MessageThreadParent]: 'The message was not sent in a guild text or news channel',
[DjsErrorCodes.MessageThreadParent]: 'The message was not sent in a guild text or announcement channel',
[DjsErrorCodes.MessageExistingThread]: 'The message already has a thread',
[DjsErrorCodes.ThreadInvitableType]: type => `Invitable cannot be edited on ${type}`,

Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ exports.MessagePayload = require('./structures/MessagePayload');
exports.MessageReaction = require('./structures/MessageReaction');
exports.ModalSubmitInteraction = require('./structures/ModalSubmitInteraction');
exports.ModalSubmitFields = require('./structures/ModalSubmitFields');
exports.NewsChannel = require('./structures/NewsChannel');
exports.AnnouncementChannel = require('./structures/AnnouncementChannel.js');
exports.OAuth2Guild = require('./structures/OAuth2Guild');
exports.PartialGroupDMChannel = require('./structures/PartialGroupDMChannel');
exports.PermissionOverwrites = require('./structures/PermissionOverwrites');
Expand Down
14 changes: 7 additions & 7 deletions packages/discord.js/src/managers/GuildChannelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ class GuildChannelManager extends CachedManager {
}

/**
* Data that can be resolved to a News Channel object. This can be:
* * A NewsChannel object
* Data that can be resolved to an Announcement Channel object. This can be:
* * An Announcement Channel object
* * A Snowflake
* @typedef {NewsChannel|Snowflake} NewsChannelResolvable
* @typedef {AnnouncementChannel|Snowflake} AnnouncementChannelResolvable
*/

/**
* Adds the target channel to a channel's followers.
* @param {NewsChannelResolvable} channel The channel to follow
* @param {AnnouncementChannelResolvable} channel The channel to follow
* @param {TextChannelResolvable} targetChannel The channel where published announcements will be posted at
* @param {string} [reason] Reason for creating the webhook
* @returns {Promise<Snowflake>} Returns created target webhook id.
*/
async addFollower(channel, targetChannel, reason) {
const channelId = this.resolveId(channel);
if (!channelId) {
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'NewsChannelResolvable');
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'AnnouncementChannelResolvable');
}
const targetChannelId = this.resolveId(targetChannel);
if (!targetChannelId) {
Expand Down Expand Up @@ -208,7 +208,7 @@ class GuildChannelManager extends CachedManager {

/**
* @typedef {ChannelWebhookCreateOptions} WebhookCreateOptions
* @property {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel|Snowflake} channel
* @property {TextChannel|AnnouncementChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel|Snowflake} channel
* The channel to create the webhook for
*/

Expand Down Expand Up @@ -247,7 +247,7 @@ class GuildChannelManager extends CachedManager {
* Options used to edit a guild channel.
* @typedef {Object} GuildChannelEditOptions
* @property {string} [name] The name of the channel
* @property {ChannelType} [type] The type of the channel (only conversion between text and news is supported)
* @property {ChannelType} [type] The type of the channel (only conversion between text and announcement is supported)
* @property {number} [position] The position of the channel
* @property {?string} [topic] The topic of the text channel
* @property {boolean} [nsfw] Whether the channel is NSFW
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/managers/GuildInviteManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class GuildInviteManager extends CachedManager {
* Data that can be resolved to a channel that an invite can be created on. This can be:
* * TextChannel
* * VoiceChannel
* * NewsChannel
* * AnnouncementChannel
* * StageChannel
* * ForumChannel
* * MediaChannel
* * Snowflake
* @typedef {TextChannel|VoiceChannel|NewsChannel|StageChannel|ForumChannel|MediaChannel|Snowflake}
* @typedef {TextChannel|VoiceChannel|AnnouncementChannel|StageChannel|ForumChannel|MediaChannel|Snowflake}
* GuildInvitableChannelResolvable
*/

Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/managers/GuildTextThreadManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GuildTextThreadManager extends ThreadManager {
/**
* The channel this Manager belongs to
* @name GuildTextThreadManager#channel
* @type {TextChannel|NewsChannel}
* @type {TextChannel|AnnouncementChannel}
*/

/**
Expand All @@ -22,7 +22,7 @@ class GuildTextThreadManager extends ThreadManager {
* <warn>If this is defined, then the `type` of thread gets inferred automatically and cannot be changed.</warn>
* @property {ThreadChannelTypes} [type] The type of thread to create.
* Defaults to {@link ChannelType.PublicThread} if created in a {@link TextChannel}
* <warn>When creating threads in a {@link NewsChannel}, this is ignored and is always
* <warn>When creating threads in a {@link AnnouncementChannel}, this is ignored and is always
* {@link ChannelType.AnnouncementThread}</warn>
* @property {boolean} [invitable] Whether non-moderators can add other non-moderators to the thread
* <info>Can only be set when type will be {@link ChannelType.PrivateThread}</info>
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/managers/ThreadManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ThreadManager extends CachedManager {

/**
* The channel this Manager belongs to
* @type {TextChannel|NewsChannel|ForumChannel|MediaChannel}
* @type {TextChannel|AnnouncementChannel|ForumChannel|MediaChannel}
*/
this.channel = channel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const BaseGuildTextChannel = require('./BaseGuildTextChannel');
const { DiscordjsError, ErrorCodes } = require('../errors');

/**
* Represents a guild news channel on Discord.
* Represents a guild announcement channel on Discord.
* @extends {BaseGuildTextChannel}
*/
class NewsChannel extends BaseGuildTextChannel {
class AnnouncementChannel extends BaseGuildTextChannel {
/**
* Adds the target to this channel's followers.
* @param {TextChannelResolvable} channel The channel where the webhook should be created
* @param {string} [reason] Reason for creating the webhook
* @returns {Promise<NewsChannel>}
* @returns {Promise<AnnouncementChannel>}
* @example
* if (channel.type === ChannelType.GuildAnnouncement) {
* channel.addFollower('222197033908436994', 'Important announcements')
Expand All @@ -29,4 +29,4 @@ class NewsChannel extends BaseGuildTextChannel {
}
}

module.exports = NewsChannel;
module.exports = AnnouncementChannel;
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/BaseGuildTextChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class BaseGuildTextChannel extends GuildChannel {

/**
* Sets the type of this channel.
* <info>Only conversion between {@link TextChannel} and {@link NewsChannel} is supported.</info>
* <info>Only conversion between {@link TextChannel} and {@link AnnouncementChannel} is supported.</info>
* @param {ChannelType.GuildText|ChannelType.GuildAnnouncement} type The new channel type
* @param {string} [reason] Reason for changing the channel's type
* @returns {Promise<GuildChannel>}
Expand Down
14 changes: 7 additions & 7 deletions packages/discord.js/src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ class Guild extends AnonymousGuild {

/**
* Widget channel for this guild
* @type {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel)}
* @type {?(TextChannel|AnnouncementChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel)}
* @readonly
*/
get widgetChannel() {
Expand Down Expand Up @@ -687,16 +687,16 @@ class Guild extends AnonymousGuild {
* Data for the Guild Widget Settings object
* @typedef {Object} GuildWidgetSettings
* @property {boolean} enabled Whether the widget is enabled
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel)} channel
* @property {?(TextChannel|AnnouncementChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel)} channel
* The widget invite channel
*/

/**
* The Guild Widget Settings object
* @typedef {Object} GuildWidgetSettingsData
* @property {boolean} enabled Whether the widget is enabled
* @property {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel|Snowflake)} channel
* The widget invite channel
* @property {?(TextChannel|AnnouncementChannel|VoiceChannel|StageChannel|ForumChannel|
* MediaChannel|Snowflake)} channel The widget invite channel
*/

/**
Expand Down Expand Up @@ -958,7 +958,7 @@ class Guild extends AnonymousGuild {
* Welcome channel data
* @typedef {Object} WelcomeChannelData
* @property {string} description The description to show for this welcome channel
* @property {TextChannel|NewsChannel|ForumChannel|MediaChannel|Snowflake} channel
* @property {TextChannel|AnnouncementChannel|ForumChannel|MediaChannel|Snowflake} channel
* The channel to link for this welcome channel
* @property {EmojiIdentifierResolvable} [emoji] The emoji to display for this welcome channel
*/
Expand All @@ -974,9 +974,9 @@ class Guild extends AnonymousGuild {
/**
* Data that can be resolved to a GuildTextChannel object. This can be:
* * A TextChannel
* * A NewsChannel
* * A AnnouncementChannel
* * A Snowflake
* @typedef {TextChannel|NewsChannel|Snowflake} GuildTextChannelResolvable
* @typedef {TextChannel|AnnouncementChannel|Snowflake} GuildTextChannelResolvable
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/GuildChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { getSortableGroupTypes } = require('../util/Util');
* - {@link TextChannel}
* - {@link VoiceChannel}
* - {@link CategoryChannel}
* - {@link NewsChannel}
* - {@link AnnouncementChannel}
* - {@link StageChannel}
* - {@link ForumChannel}
* - {@link MediaChannel}
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/ThreadChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class ThreadChannel extends BaseChannel {

/**
* The parent channel of this thread
* @type {?(NewsChannel|TextChannel|ForumChannel|MediaChannel)}
* @type {?(AnnouncementChannel|TextChannel|ForumChannel|MediaChannel)}
* @readonly
*/
get parent() {
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/structures/Webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Webhook {
if ('source_channel' in data) {
/**
* The source channel of the webhook
* @type {?(NewsChannel|APIChannel)}
* @type {?(AnnouncementChannel|APIChannel)}
*/
this.sourceChannel = this.client.channels?.resolve(data.source_channel?.id) ?? data.source_channel;
} else {
Expand Down Expand Up @@ -149,7 +149,7 @@ class Webhook {

/**
* The channel the webhook belongs to
* @type {?(TextChannel|VoiceChannel|StageChannel|NewsChannel|ForumChannel|MediaChannel)}
* @type {?(TextChannel|VoiceChannel|StageChannel|AnnouncementChannel|ForumChannel|MediaChannel)}
* @readonly
*/
get channel() {
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/WelcomeChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class WelcomeChannel extends Base {

/**
* The channel of this welcome channel
* @type {?(TextChannel|NewsChannel|ForumChannel|MediaChannel)}
* @type {?(TextChannel|AnnouncementChannel|ForumChannel|MediaChannel)}
*/
get channel() {
return this.client.channels.resolve(this.channelId);
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/util/Channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { ChannelType } = require('discord-api-types/v10');

const getCategoryChannel = lazy(() => require('../structures/CategoryChannel'));
const getDMChannel = lazy(() => require('../structures/DMChannel'));
const getNewsChannel = lazy(() => require('../structures/NewsChannel'));
const getAnnouncementChannel = lazy(() => require('../structures/AnnouncementChannel'));
const getStageChannel = lazy(() => require('../structures/StageChannel'));
const getTextChannel = lazy(() => require('../structures/TextChannel'));
const getThreadChannel = lazy(() => require('../structures/ThreadChannel'));
Expand Down Expand Up @@ -57,7 +57,7 @@ function createChannel(client, data, guild, { allowUnknownGuild } = {}) {
break;
}
case ChannelType.GuildAnnouncement: {
channel = new (getNewsChannel())(guild, data, client);
channel = new (getAnnouncementChannel())(guild, data, client);
break;
}
case ChannelType.GuildStageVoice: {
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/util/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ exports.NonSystemMessageTypes = [
/**
* The guild channels that are text-based.
* * TextChannel
* * NewsChannel
* * AnnouncementChannel
* * ThreadChannel
* * VoiceChannel
* * StageChannel
* @typedef {TextChannel|NewsChannel|ThreadChannel|VoiceChannel|StageChannel} GuildTextBasedChannel
* @typedef {TextChannel|AnnouncementChannel|ThreadChannel|VoiceChannel|StageChannel} GuildTextBasedChannel
*/

/**
Expand Down
Loading

0 comments on commit c8ef899

Please sign in to comment.