Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace usage of deprecated ChannelTypes #8625

Merged
merged 2 commits into from Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -234,7 +234,7 @@ describe('Slash Commands', () => {

expect(() => {
getBuilder().addChannelOption(
getChannelOption().addChannelTypes(ChannelType.GuildNews, ChannelType.GuildText),
getChannelOption().addChannelTypes(ChannelType.GuildAnnouncement, ChannelType.GuildText),
);
}).not.toThrowError();
});
Expand Down
Expand Up @@ -6,10 +6,10 @@ const allowedChannelTypes = [
ChannelType.GuildText,
ChannelType.GuildVoice,
ChannelType.GuildCategory,
ChannelType.GuildNews,
ChannelType.GuildNewsThread,
ChannelType.GuildPublicThread,
ChannelType.GuildPrivateThread,
ChannelType.GuildAnnouncement,
ChannelType.AnnouncementThread,
ChannelType.PublicThread,
ChannelType.PrivateThread,
ChannelType.GuildStageVoice,
] as const;

Expand Down
16 changes: 8 additions & 8 deletions packages/discord.js/src/managers/ThreadManager.js
Expand Up @@ -65,13 +65,13 @@ class ThreadManager extends CachedManager {
* @typedef {StartThreadOptions} ThreadCreateOptions
* @property {MessageResolvable} [startMessage] The message to start a thread from. <warn>If this is defined then type
* of thread gets automatically defined and cannot be changed. The provided `type` field will be ignored</warn>
* @property {ChannelType.GuildNewsThread|ChannelType.GuildPublicThread|ChannelType.GuildPrivateThread} [type]
* @property {ChannelType.AnnouncementThread|ChannelType.PublicThread|ChannelType.PrivateThread} [type]
* The type of thread to create.
* Defaults to {@link ChannelType.GuildPublicThread} if created in a {@link TextChannel}
* 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
* {@link ChannelType.GuildNewsThread}</warn>
* {@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.GuildPrivateThread}</info>
* <info>Can only be set when type will be {@link ChannelType.PrivateThread}</info>
*/

/**
Expand All @@ -94,7 +94,7 @@ class ThreadManager extends CachedManager {
* .create({
* name: 'mod-talk',
* autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
* type: ChannelType.GuildPrivateThread,
* type: ChannelType.PrivateThread,
* reason: 'Needed a separate thread for moderation',
* })
* .then(threadChannel => console.log(threadChannel))
Expand All @@ -113,12 +113,12 @@ class ThreadManager extends CachedManager {
throw new TypeError(ErrorCodes.InvalidType, 'type', 'ThreadChannelType or Number');
}
let resolvedType =
this.channel.type === ChannelType.GuildNews ? ChannelType.GuildNewsThread : ChannelType.GuildPublicThread;
this.channel.type === ChannelType.GuildAnnouncement ? ChannelType.AnnouncementThread : ChannelType.PublicThread;
let startMessageId;
if (startMessage) {
startMessageId = this.channel.messages.resolveId(startMessage);
if (!startMessageId) throw new TypeError(ErrorCodes.InvalidType, 'startMessage', 'MessageResolvable');
} else if (this.channel.type !== ChannelType.GuildNews) {
} else if (this.channel.type !== ChannelType.GuildAnnouncement) {
resolvedType = type ?? resolvedType;
}

Expand All @@ -127,7 +127,7 @@ class ThreadManager extends CachedManager {
name,
auto_archive_duration: autoArchiveDuration,
type: resolvedType,
invitable: resolvedType === ChannelType.GuildPrivateThread ? invitable : undefined,
invitable: resolvedType === ChannelType.PrivateThread ? invitable : undefined,
rate_limit_per_user: rateLimitPerUser,
},
reason,
Expand Down
Expand Up @@ -92,7 +92,7 @@ class BaseGuildTextChannel extends GuildChannel {
/**
* Sets the type of this channel.
* <info>Only conversion between {@link TextChannel} and {@link NewsChannel} is supported.</info>
* @param {ChannelType.GuildText|ChannelType.GuildNews} type The new channel type
* @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
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/Guild.js
Expand Up @@ -1277,7 +1277,7 @@ class Guild extends AnonymousGuild {
*/
_sortedChannels(channel) {
const category = channel.type === ChannelType.GuildCategory;
const channelTypes = [ChannelType.GuildText, ChannelType.GuildNews];
const channelTypes = [ChannelType.GuildText, ChannelType.GuildAnnouncement];
return discordSort(
this.channels.cache.filter(
c =>
Expand Down
6 changes: 3 additions & 3 deletions packages/discord.js/src/structures/Message.js
Expand Up @@ -636,7 +636,7 @@ class Message extends Base {
(this.author.id === this.client.user.id ? PermissionsBitField.DefaultBit : PermissionFlagsBits.ManageMessages);
const { channel } = this;
return Boolean(
channel?.type === ChannelType.GuildNews &&
channel?.type === ChannelType.GuildAnnouncement &&
!this.flags.has(MessageFlags.Crossposted) &&
this.type === MessageType.Default &&
channel.viewable &&
Expand Down Expand Up @@ -664,7 +664,7 @@ class Message extends Base {
* @returns {Promise<Message>}
* @example
* // Crosspost a message
* if (message.channel.type === ChannelType.GuildNews) {
* if (message.channel.type === ChannelType.GuildAnnouncement) {
* message.crosspost()
* .then(() => console.log('Crossposted message'))
* .catch(console.error);
Expand Down Expand Up @@ -806,7 +806,7 @@ class Message extends Base {
*/
startThread(options = {}) {
if (!this.channel) return Promise.reject(new Error(ErrorCodes.ChannelNotCached));
if (![ChannelType.GuildText, ChannelType.GuildNews].includes(this.channel.type)) {
if (![ChannelType.GuildText, ChannelType.GuildAnnouncement].includes(this.channel.type)) {
return Promise.reject(new Error(ErrorCodes.MessageThreadParent));
}
if (this.hasThread) return Promise.reject(new Error(ErrorCodes.MessageExistingThread));
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/NewsChannel.js
Expand Up @@ -15,7 +15,7 @@ class NewsChannel extends BaseGuildTextChannel {
* @param {string} [reason] Reason for creating the webhook
* @returns {Promise<NewsChannel>}
* @example
* if (channel.type === ChannelType.GuildNews) {
* if (channel.type === ChannelType.GuildAnnouncement) {
* channel.addFollower('222197033908436994', 'Important announcements')
* .then(() => console.log('Added follower'))
* .catch(console.error);
Expand Down
18 changes: 8 additions & 10 deletions packages/discord.js/src/structures/ThreadChannel.js
Expand Up @@ -80,7 +80,7 @@ class ThreadChannel extends BaseChannel {
* <info>This property is always `null` in public threads.</info>
* @type {?boolean}
*/
this.invitable = this.type === ChannelType.GuildPrivateThread ? data.thread_metadata.invitable ?? false : null;
this.invitable = this.type === ChannelType.PrivateThread ? data.thread_metadata.invitable ?? false : null;

/**
* Whether the thread is archived
Expand Down Expand Up @@ -114,7 +114,7 @@ class ThreadChannel extends BaseChannel {
this.invitable ??= null;
}

this._createdTimestamp ??= this.type === ChannelType.GuildPrivateThread ? super.createdTimestamp : null;
this._createdTimestamp ??= this.type === ChannelType.PrivateThread ? super.createdTimestamp : null;

if ('owner_id' in data) {
/**
Expand Down Expand Up @@ -301,7 +301,7 @@ class ThreadChannel extends BaseChannel {
* @property {boolean} [locked] Whether the thread is locked
* @property {boolean} [invitable] Whether non-moderators can add other non-moderators to a thread
* @property {string} [reason] Reason for editing the thread
* <info>Can only be edited on {@link ChannelType.GuildPrivateThread}</info>
* <info>Can only be edited on {@link ChannelType.PrivateThread}</info>
*/

/**
Expand All @@ -322,7 +322,7 @@ class ThreadChannel extends BaseChannel {
auto_archive_duration: data.autoArchiveDuration,
rate_limit_per_user: data.rateLimitPerUser,
locked: data.locked,
invitable: this.type === ChannelType.GuildPrivateThread ? data.invitable : undefined,
invitable: this.type === ChannelType.PrivateThread ? data.invitable : undefined,
},
reason: data.reason,
});
Expand Down Expand Up @@ -371,7 +371,7 @@ class ThreadChannel extends BaseChannel {
* @returns {Promise<ThreadChannel>}
*/
setInvitable(invitable = true, reason) {
if (this.type !== ChannelType.GuildPrivateThread) {
if (this.type !== ChannelType.PrivateThread) {
return Promise.reject(new RangeError(ErrorCodes.ThreadInvitableType, this.type));
}
return this.edit({ invitable, reason });
Expand Down Expand Up @@ -435,7 +435,7 @@ class ThreadChannel extends BaseChannel {
*/
get editable() {
return (
(this.ownerId === this.client.user.id && (this.type !== ChannelType.GuildPrivateThread || this.joined)) ||
(this.ownerId === this.client.user.id && (this.type !== ChannelType.PrivateThread || this.joined)) ||
this.manageable
);
}
Expand All @@ -450,9 +450,7 @@ class ThreadChannel extends BaseChannel {
!this.archived &&
!this.joined &&
this.permissionsFor(this.client.user)?.has(
this.type === ChannelType.GuildPrivateThread
? PermissionFlagsBits.ManageThreads
: PermissionFlagsBits.ViewChannel,
this.type === ChannelType.PrivateThread ? PermissionFlagsBits.ManageThreads : PermissionFlagsBits.ViewChannel,
false,
)
);
Expand Down Expand Up @@ -500,7 +498,7 @@ class ThreadChannel extends BaseChannel {

return (
!(this.archived && this.locked && !this.manageable) &&
(this.type !== ChannelType.GuildPrivateThread || this.joined || this.manageable) &&
(this.type !== ChannelType.PrivateThread || this.joined || this.manageable) &&
permissions.has(PermissionFlagsBits.SendMessagesInThreads, false) &&
this.guild.members.me.communicationDisabledUntilTimestamp < Date.now()
);
Expand Down
8 changes: 4 additions & 4 deletions packages/discord.js/src/util/Channels.js
Expand Up @@ -47,17 +47,17 @@ function createChannel(client, data, guild, { allowUnknownGuild, fromInteraction
channel = new (getCategoryChannel())(guild, data, client);
break;
}
case ChannelType.GuildNews: {
case ChannelType.GuildAnnouncement: {
channel = new (getNewsChannel())(guild, data, client);
break;
}
case ChannelType.GuildStageVoice: {
channel = new (getStageChannel())(guild, data, client);
break;
}
case ChannelType.GuildNewsThread:
case ChannelType.GuildPublicThread:
case ChannelType.GuildPrivateThread: {
case ChannelType.AnnouncementThread:
case ChannelType.PublicThread:
case ChannelType.PrivateThread: {
channel = new (getThreadChannel())(guild, data, client, fromInteraction);
if (!allowUnknownGuild) channel.parent?.threads.cache.set(channel.id, channel);
break;
Expand Down
28 changes: 12 additions & 16 deletions packages/discord.js/src/util/Constants.js
Expand Up @@ -79,35 +79,31 @@ exports.NonSystemMessageTypes = [
* The types of channels that are text-based. The available types are:
* * {@link ChannelType.DM}
* * {@link ChannelType.GuildText}
* * {@link ChannelType.GuildNews}
* * {@link ChannelType.GuildNewsThread}
* * {@link ChannelType.GuildPublicThread}
* * {@link ChannelType.GuildPrivateThread}
* * {@link ChannelType.GuildAnnouncement}
* * {@link ChannelType.AnnouncementThread}
* * {@link ChannelType.PublicThread}
* * {@link ChannelType.PrivateThread}
* * {@link ChannelType.GuildVoice}
* @typedef {ChannelType[]} TextBasedChannelTypes
*/
exports.TextBasedChannelTypes = [
ChannelType.DM,
ChannelType.GuildText,
ChannelType.GuildNews,
ChannelType.GuildNewsThread,
ChannelType.GuildPublicThread,
ChannelType.GuildPrivateThread,
ChannelType.GuildAnnouncement,
ChannelType.AnnouncementThread,
ChannelType.PublicThread,
ChannelType.PrivateThread,
ChannelType.GuildVoice,
];

/**
* The types of channels that are threads. The available types are:
* * {@link ChannelType.GuildNewsThread}
* * {@link ChannelType.GuildPublicThread}
* * {@link ChannelType.GuildPrivateThread}
* * {@link ChannelType.AnnouncementThread}
* * {@link ChannelType.PublicThread}
* * {@link ChannelType.PrivateThread}
* @typedef {ChannelType[]} ThreadChannelTypes
*/
exports.ThreadChannelTypes = [
ChannelType.GuildNewsThread,
ChannelType.GuildPublicThread,
ChannelType.GuildPrivateThread,
];
exports.ThreadChannelTypes = [ChannelType.AnnouncementThread, ChannelType.PublicThread, ChannelType.PrivateThread];

/**
* The types of channels that are voice-based. The available types are:
Expand Down
35 changes: 16 additions & 19 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -515,7 +515,7 @@ export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel, tr
): Promise<this>;
public setTopic(topic: string | null, reason?: string): Promise<this>;
public setType(type: ChannelType.GuildText, reason?: string): Promise<TextChannel>;
public setType(type: ChannelType.GuildNews, reason?: string): Promise<NewsChannel>;
public setType(type: ChannelType.GuildAnnouncement, reason?: string): Promise<NewsChannel>;
}

export class BaseGuildVoiceChannel extends GuildChannel {
Expand Down Expand Up @@ -699,7 +699,7 @@ export class Embed {
}

export interface MappedChannelCategoryTypes {
[ChannelType.GuildNews]: NewsChannel;
[ChannelType.GuildAnnouncement]: NewsChannel;
[ChannelType.GuildVoice]: VoiceChannel;
[ChannelType.GuildText]: TextChannel;
[ChannelType.GuildStageVoice]: StageChannel;
Expand All @@ -710,9 +710,9 @@ export type CategoryChannelType = Exclude<
ChannelType,
| ChannelType.DM
| ChannelType.GroupDM
| ChannelType.GuildPublicThread
| ChannelType.GuildNewsThread
| ChannelType.GuildPrivateThread
| ChannelType.PublicThread
| ChannelType.AnnouncementThread
| ChannelType.PrivateThread
| ChannelType.GuildCategory
| ChannelType.GuildDirectory
>;
Expand Down Expand Up @@ -2013,7 +2013,7 @@ export class ModalSubmitInteraction<Cached extends CacheType = CacheType> extend

export class NewsChannel extends BaseGuildTextChannel {
public threads: ThreadManager<AllowedThreadTypeForNewsChannel>;
public type: ChannelType.GuildNews;
public type: ChannelType.GuildAnnouncement;
public addFollower(channel: TextChannelResolvable, reason?: string): Promise<NewsChannel>;
}

Expand Down Expand Up @@ -2490,13 +2490,13 @@ export class TextChannel extends BaseGuildTextChannel {
export type AnyThreadChannel = PublicThreadChannel | PrivateThreadChannel;

export interface PublicThreadChannel extends ThreadChannel {
type: ChannelType.GuildPublicThread | ChannelType.GuildNewsThread;
type: ChannelType.PublicThread | ChannelType.AnnouncementThread;
}

export interface PrivateThreadChannel extends ThreadChannel {
get createdTimestamp(): number;
get createdAt(): Date;
type: ChannelType.GuildPrivateThread;
type: ChannelType.PrivateThread;
}

export class ThreadChannel extends TextBasedChannelMixin(BaseChannel, true, [
Expand Down Expand Up @@ -3753,9 +3753,9 @@ export interface AddGuildMemberOptions {

export type AllowedPartial = User | Channel | GuildMember | Message | MessageReaction | ThreadMember;

export type AllowedThreadTypeForNewsChannel = ChannelType.GuildNewsThread;
export type AllowedThreadTypeForNewsChannel = ChannelType.AnnouncementThread;

export type AllowedThreadTypeForTextChannel = ChannelType.GuildPublicThread | ChannelType.GuildPrivateThread;
export type AllowedThreadTypeForTextChannel = ChannelType.PublicThread | ChannelType.PrivateThread;

export interface BaseApplicationCommandData {
name: string;
Expand Down Expand Up @@ -4804,9 +4804,9 @@ export interface GuildChannelCreateOptions extends Omit<CategoryCreateChannelOpt
ChannelType,
| ChannelType.DM
| ChannelType.GroupDM
| ChannelType.GuildPublicThread
| ChannelType.GuildNewsThread
| ChannelType.GuildPrivateThread
| ChannelType.PublicThread
| ChannelType.AnnouncementThread
| ChannelType.PrivateThread
>;
}

Expand All @@ -4816,7 +4816,7 @@ export interface GuildChannelCloneOptions extends Omit<GuildChannelCreateOptions

export interface GuildChannelEditOptions {
name?: string;
type?: ChannelType.GuildText | ChannelType.GuildNews;
type?: ChannelType.GuildText | ChannelType.GuildAnnouncement;
position?: number;
topic?: string | null;
nsfw?: boolean;
Expand Down Expand Up @@ -5554,15 +5554,12 @@ export type TextBasedChannelResolvable = Snowflake | TextBasedChannel;

export type ThreadChannelResolvable = AnyThreadChannel | Snowflake;

export type ThreadChannelType =
| ChannelType.GuildNewsThread
| ChannelType.GuildPublicThread
| ChannelType.GuildPrivateThread;
export type ThreadChannelType = ChannelType.AnnouncementThread | ChannelType.PublicThread | ChannelType.PrivateThread;

export interface ThreadCreateOptions<AllowedThreadType> extends StartThreadOptions {
startMessage?: MessageResolvable;
type?: AllowedThreadType;
invitable?: AllowedThreadType extends ChannelType.GuildPrivateThread ? boolean : never;
invitable?: AllowedThreadType extends ChannelType.PrivateThread ? boolean : never;
}

export interface ThreadEditData {
Expand Down