mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
refactor(Channel): change channel types to UPPER_CASE (#6035)
This commit is contained in:
@@ -12,7 +12,7 @@ class ChannelUpdateAction extends Action {
|
||||
if (channel) {
|
||||
const old = channel._update(data);
|
||||
|
||||
if (ChannelTypes[channel.type.toUpperCase()] !== data.type) {
|
||||
if (ChannelTypes[channel.type] !== data.type) {
|
||||
const newChannel = Channel.create(this.client, data, channel.guild);
|
||||
for (const [id, message] of channel.messages.cache) newChannel.messages.cache.set(id, message);
|
||||
newChannel._typing = new Map(channel._typing);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
const { Events, TextBasedChannelTypes } = require('../../util/Constants');
|
||||
|
||||
class GuildDeleteAction extends Action {
|
||||
constructor(client) {
|
||||
@@ -15,7 +15,7 @@ class GuildDeleteAction extends Action {
|
||||
let guild = client.guilds.cache.get(data.id);
|
||||
if (guild) {
|
||||
for (const channel of guild.channels.cache.values()) {
|
||||
if (channel.type === 'text') channel.stopTyping(true);
|
||||
if (channel.type in TextBasedChannelTypes) channel.stopTyping(true);
|
||||
}
|
||||
|
||||
if (data.unavailable) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
|
||||
const { PartialTypes } = require('../../util/Constants');
|
||||
|
||||
/*
|
||||
@@ -23,7 +23,7 @@ class MessageReactionAdd extends Action {
|
||||
|
||||
// Verify channel
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel || channel.type === 'voice') return false;
|
||||
if (!channel || channel.type in VoiceBasedChannelTypes) return false;
|
||||
|
||||
// Verify message
|
||||
const message = this.getMessage(data, channel);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
|
||||
|
||||
/*
|
||||
{ user_id: 'id',
|
||||
@@ -20,7 +20,7 @@ class MessageReactionRemove extends Action {
|
||||
|
||||
// Verify channel
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel || channel.type === 'voice') return false;
|
||||
if (!channel || channel.type in VoiceBasedChannelTypes) return false;
|
||||
|
||||
// Verify message
|
||||
const message = this.getMessage(data, channel);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
|
||||
|
||||
class MessageReactionRemoveAll extends Action {
|
||||
handle(data) {
|
||||
// Verify channel
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel || channel.type === 'voice') return false;
|
||||
if (!channel || channel.type in VoiceBasedChannelTypes) return false;
|
||||
|
||||
// Verify message
|
||||
const message = this.getMessage(data, channel);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
|
||||
|
||||
class MessageReactionRemoveEmoji extends Action {
|
||||
handle(data) {
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel || channel.type === 'voice') return false;
|
||||
if (!channel || channel.type in VoiceBasedChannelTypes) return false;
|
||||
|
||||
const message = this.getMessage(data, channel);
|
||||
if (!message) return false;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
const textBasedChannelTypes = ['dm', 'text', 'news', 'news_thread', 'public_thread', 'private_thread'];
|
||||
const { Events, TextBasedChannelTypes } = require('../../util/Constants');
|
||||
|
||||
class TypingStart extends Action {
|
||||
handle(data) {
|
||||
@@ -10,7 +9,7 @@ class TypingStart extends Action {
|
||||
if (!channel) {
|
||||
return;
|
||||
}
|
||||
if (!textBasedChannelTypes.includes(channel.type)) {
|
||||
if (!(channel.type in TextBasedChannelTypes)) {
|
||||
this.client.emit(Events.WARN, `Discord sent a typing packet to a ${channel.type} channel ${channel.id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ class GuildChannelManager extends CachedManager {
|
||||
/**
|
||||
* Options used to create a new channel in a guild.
|
||||
* @typedef {Object} GuildChannelCreateOptions
|
||||
* @property {string} [type='text'] The type of the new channel, either `text`, `voice`, `category`, `news`,
|
||||
* `store`, or `stage`
|
||||
* @property {string|number} [type='GUILD_TEXT'] The type of the new channel, either `GUILD_TEXT`, `GUILD_VOICE`,
|
||||
* `GUILD_CATEGORY`, `GUILD_NEWS`, `GUILD_STORE`, or `GUILD_STAGE_VOICE`
|
||||
* @property {string} [topic] The topic for the new channel
|
||||
* @property {boolean} [nsfw] Whether the new channel is nsfw
|
||||
* @property {number} [bitrate] Bitrate of the new channel in bits (only voice)
|
||||
@@ -107,7 +107,7 @@ class GuildChannelManager extends CachedManager {
|
||||
* @example
|
||||
* // Create a new channel with permission overwrites
|
||||
* guild.channels.create('new-voice', {
|
||||
* type: 'voice',
|
||||
* type: 'GUILD_VOICE',
|
||||
* permissionOverwrites: [
|
||||
* {
|
||||
* id: message.author.id,
|
||||
@@ -129,7 +129,7 @@ class GuildChannelManager extends CachedManager {
|
||||
data: {
|
||||
name,
|
||||
topic,
|
||||
type: type ? ChannelTypes[type.toUpperCase()] : ChannelTypes.TEXT,
|
||||
type: typeof type === 'number' ? type : ChannelTypes[type] ?? ChannelTypes.GUILD_TEXT,
|
||||
nsfw,
|
||||
bitrate,
|
||||
user_limit: userLimit,
|
||||
|
||||
@@ -75,7 +75,7 @@ class GuildManager extends CachedManager {
|
||||
* @property {Snowflake|number} [id] The channel's id, used to set its parent,
|
||||
* this is a placeholder and will be replaced by the API after consumption
|
||||
* @property {Snowflake|number} [parentId] The parent id for this channel
|
||||
* @property {string} [type] The type of the channel
|
||||
* @property {ChannelType} [type] The type of the channel
|
||||
* @property {string} name The name of the channel
|
||||
* @property {string} [topic] The topic of the text channel
|
||||
* @property {boolean} [nsfw] Whether the channel is NSFW
|
||||
|
||||
@@ -77,9 +77,9 @@ class ThreadManager extends CachedManager {
|
||||
* should automatically archive in case of no recent activity
|
||||
* @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 {ThreadChannelType|number} [type] The type of thread to create. Defaults to `public_thread` if created in
|
||||
* a {@link TextChannel} <warn>When creating threads in a {@link NewsChannel} this is ignored and is always
|
||||
* `news_thread`</warn>
|
||||
* @property {ThreadChannelTypes|number} [type] The type of thread to create. Defaults to `GUILD_PUBLIC_THREAD` if
|
||||
* created in a {@link TextChannel} <warn>When creating threads in a {@link NewsChannel} this is ignored and is always
|
||||
* `GUILD_NEWS_THREAD`</warn>
|
||||
* @property {string} [reason] Reason for creating the thread
|
||||
*/
|
||||
|
||||
@@ -103,7 +103,7 @@ class ThreadManager extends CachedManager {
|
||||
* .create({
|
||||
* name: 'mod-talk',
|
||||
* autoArchiveDuration: 60,
|
||||
* type: 'private_thread',
|
||||
* type: 'GUILD_PRIVATE_THREAD',
|
||||
* reason: 'Needed a separate thread for moderation',
|
||||
* })
|
||||
* .then(threadChannel => console.log(threadChannel))
|
||||
@@ -114,13 +114,14 @@ class ThreadManager extends CachedManager {
|
||||
if (type && typeof type !== 'string' && typeof type !== 'number') {
|
||||
throw new TypeError('INVALID_TYPE', 'type', 'ThreadChannelType or Number');
|
||||
}
|
||||
let resolvedType = this.channel.type === 'news' ? ChannelTypes.NEWS_THREAD : ChannelTypes.PUBLIC_THREAD;
|
||||
let resolvedType =
|
||||
this.channel.type === 'GUILD_NEWS' ? ChannelTypes.GUILD_NEWS_THREAD : ChannelTypes.GUILD_PUBLIC_THREAD;
|
||||
if (startMessage) {
|
||||
const startMessageId = this.channel.messages.resolveId(startMessage);
|
||||
if (!startMessageId) throw new TypeError('INVALID_TYPE', 'startMessage', 'MessageResolvable');
|
||||
path = path.messages(startMessageId);
|
||||
} else if (this.channel.type !== 'news') {
|
||||
resolvedType = typeof type === 'string' ? ChannelTypes[type.toUpperCase()] : type ?? resolvedType;
|
||||
} else if (this.channel.type !== 'GUILD_NEWS') {
|
||||
resolvedType = typeof type === 'string' ? ChannelTypes[type] : type ?? resolvedType;
|
||||
}
|
||||
|
||||
const data = await path.threads.post({
|
||||
|
||||
@@ -23,21 +23,10 @@ class Channel extends Base {
|
||||
|
||||
const type = ChannelTypes[data.type];
|
||||
/**
|
||||
* The type of the channel, either:
|
||||
* * `dm` - a DM channel
|
||||
* * `text` - a guild text channel
|
||||
* * `voice` - a guild voice channel
|
||||
* * `category` - a guild category channel
|
||||
* * `news` - a guild news channel
|
||||
* * `store` - a guild store channel
|
||||
* * `news_thread` - a guild news channel's public thread channel
|
||||
* * `public_thread` - a guild text channel's public thread channel
|
||||
* * `private_thread` - a guild text channel's private thread channel
|
||||
* * `stage` - a guild stage channel
|
||||
* * `unknown` - a generic channel of unknown type, could be Channel or GuildChannel
|
||||
* @type {string}
|
||||
* The type of the channel
|
||||
* @type {ChannelType}
|
||||
*/
|
||||
this.type = type?.toLowerCase() ?? 'unknown';
|
||||
this.type = type ?? 'UNKNOWN';
|
||||
|
||||
/**
|
||||
* Whether the channel has been deleted
|
||||
@@ -139,9 +128,9 @@ class Channel extends Base {
|
||||
|
||||
let channel;
|
||||
if (!data.guild_id && !guild) {
|
||||
if ((data.recipients && data.type !== ChannelTypes.GROUP) || data.type === ChannelTypes.DM) {
|
||||
if ((data.recipients && data.type !== ChannelTypes.GROUP_DM) || data.type === ChannelTypes.DM) {
|
||||
channel = new DMChannel(client, data);
|
||||
} else if (data.type === ChannelTypes.GROUP) {
|
||||
} else if (data.type === ChannelTypes.GROUP_DM) {
|
||||
const PartialGroupDMChannel = require('./PartialGroupDMChannel');
|
||||
channel = new PartialGroupDMChannel(client, data);
|
||||
}
|
||||
@@ -150,33 +139,33 @@ class Channel extends Base {
|
||||
|
||||
if (guild || allowUnknownGuild) {
|
||||
switch (data.type) {
|
||||
case ChannelTypes.TEXT: {
|
||||
case ChannelTypes.GUILD_TEXT: {
|
||||
channel = new TextChannel(guild, data, client);
|
||||
break;
|
||||
}
|
||||
case ChannelTypes.VOICE: {
|
||||
case ChannelTypes.GUILD_VOICE: {
|
||||
channel = new VoiceChannel(guild, data, client);
|
||||
break;
|
||||
}
|
||||
case ChannelTypes.CATEGORY: {
|
||||
case ChannelTypes.GUILD_CATEGORY: {
|
||||
channel = new CategoryChannel(guild, data, client);
|
||||
break;
|
||||
}
|
||||
case ChannelTypes.NEWS: {
|
||||
case ChannelTypes.GUILD_NEWS: {
|
||||
channel = new NewsChannel(guild, data, client);
|
||||
break;
|
||||
}
|
||||
case ChannelTypes.STORE: {
|
||||
case ChannelTypes.GUILD_STORE: {
|
||||
channel = new StoreChannel(guild, data, client);
|
||||
break;
|
||||
}
|
||||
case ChannelTypes.STAGE: {
|
||||
case ChannelTypes.GUILD_STAGE_VOICE: {
|
||||
channel = new StageChannel(guild, data, client);
|
||||
break;
|
||||
}
|
||||
case ChannelTypes.NEWS_THREAD:
|
||||
case ChannelTypes.PUBLIC_THREAD:
|
||||
case ChannelTypes.PRIVATE_THREAD: {
|
||||
case ChannelTypes.GUILD_NEWS_THREAD:
|
||||
case ChannelTypes.GUILD_PUBLIC_THREAD:
|
||||
case ChannelTypes.GUILD_PRIVATE_THREAD: {
|
||||
channel = new ThreadChannel(guild, data, client);
|
||||
if (!allowUnknownGuild) channel.parent?.threads.cache.set(channel.id, channel);
|
||||
break;
|
||||
|
||||
@@ -17,7 +17,7 @@ class DMChannel extends Channel {
|
||||
constructor(client, data) {
|
||||
super(client, data);
|
||||
// Override the channel type so partials have a known type
|
||||
this.type = 'dm';
|
||||
this.type = 'DM';
|
||||
/**
|
||||
* A manager of the messages belonging to this channel
|
||||
* @type {MessageManager}
|
||||
|
||||
@@ -1358,12 +1358,12 @@ class Guild extends AnonymousGuild {
|
||||
* @private
|
||||
*/
|
||||
_sortedChannels(channel) {
|
||||
const category = channel.type === ChannelTypes.CATEGORY;
|
||||
const category = channel.type === ChannelTypes.GUILD_CATEGORY;
|
||||
return Util.discordSort(
|
||||
this.channels.cache.filter(
|
||||
c =>
|
||||
(['text', 'news', 'store'].includes(channel.type)
|
||||
? ['text', 'news', 'store'].includes(c.type)
|
||||
(['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_STORE'].includes(channel.type)
|
||||
? ['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_STORE'].includes(c.type)
|
||||
: c.type === channel.type) &&
|
||||
(category || c.parent === channel.parent),
|
||||
),
|
||||
|
||||
@@ -5,7 +5,7 @@ const PermissionOverwrites = require('./PermissionOverwrites');
|
||||
const { Error } = require('../errors');
|
||||
const PermissionOverwriteManager = require('../managers/PermissionOverwriteManager');
|
||||
const Collection = require('../util/Collection');
|
||||
const { ChannelTypes } = require('../util/Constants');
|
||||
const { ChannelTypes, VoiceBasedChannelTypes } = require('../util/Constants');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
@@ -265,7 +265,7 @@ class GuildChannel extends Channel {
|
||||
* The data for a guild channel.
|
||||
* @typedef {Object} ChannelData
|
||||
* @property {string} [name] The name of the channel
|
||||
* @property {string} [type] The type of the the channel (only conversion between text and news is supported)
|
||||
* @property {ChannelType} [type] The type of the the channel (only conversion between text and news 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
|
||||
@@ -319,7 +319,7 @@ class GuildChannel extends Channel {
|
||||
if (data.lockPermissions) {
|
||||
if (data.parentId) {
|
||||
const newParent = this.guild.channels.resolve(data.parentId);
|
||||
if (newParent?.type === 'category') {
|
||||
if (newParent?.type === 'GUILD_CATEGORY') {
|
||||
permission_overwrites = newParent.permissionOverwrites.cache.map(o =>
|
||||
PermissionOverwrites.resolve(o, this.guild),
|
||||
);
|
||||
@@ -334,7 +334,7 @@ class GuildChannel extends Channel {
|
||||
const newData = await this.client.api.channels(this.id).patch({
|
||||
data: {
|
||||
name: (data.name ?? this.name).trim(),
|
||||
type: ChannelTypes[data.type?.toUpperCase()],
|
||||
type: ChannelTypes[data.type],
|
||||
topic: data.topic,
|
||||
nsfw: data.nsfw,
|
||||
bitrate: data.bitrate ?? this.bitrate,
|
||||
@@ -567,7 +567,7 @@ class GuildChannel extends Channel {
|
||||
*/
|
||||
get manageable() {
|
||||
if (this.client.user.id === this.guild.ownerId) return true;
|
||||
if (this.type === 'voice' || this.type === 'stage') {
|
||||
if (this.type in VoiceBasedChannelTypes) {
|
||||
if (!this.permissionsFor(this.client.user).has(Permissions.FLAGS.CONNECT, false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -552,7 +552,7 @@ class Message extends Base {
|
||||
*/
|
||||
get crosspostable() {
|
||||
return (
|
||||
this.channel.type === 'news' &&
|
||||
this.channel.type === 'GUILD_NEWS' &&
|
||||
!this.flags.has(MessageFlags.FLAGS.CROSSPOSTED) &&
|
||||
this.type === 'DEFAULT' &&
|
||||
this.channel.viewable &&
|
||||
@@ -595,7 +595,7 @@ class Message extends Base {
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
* // Crosspost a message
|
||||
* if (message.channel.type === 'news') {
|
||||
* if (message.channel.type === 'GUILD_NEWS') {
|
||||
* message.crosspost()
|
||||
* .then(() => console.log('Crossposted message'))
|
||||
* .catch(console.error);
|
||||
@@ -713,7 +713,7 @@ class Message extends Base {
|
||||
* @returns {Promise<ThreadChannel>}
|
||||
*/
|
||||
startThread(name, autoArchiveDuration, reason) {
|
||||
if (!['text', 'news'].includes(this.channel.type)) {
|
||||
if (!['GUILD_TEXT', 'GUILD_NEWS'].includes(this.channel.type)) {
|
||||
return Promise.reject(new Error('MESSAGE_THREAD_PARENT'));
|
||||
}
|
||||
return this.channel.threads.create({ name, autoArchiveDuration, startMessage: this, reason });
|
||||
|
||||
@@ -117,7 +117,7 @@ class MessageMentions {
|
||||
this.crosspostedChannels.set(d.id, {
|
||||
channelId: d.id,
|
||||
guildId: d.guild_id,
|
||||
type: type?.toLowerCase() ?? 'unknown',
|
||||
type: type ?? 'UNKNOWN',
|
||||
name: d.name,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class NewsChannel extends TextChannel {
|
||||
* @param {string} [reason] Reason for creating the webhook
|
||||
* @returns {Promise<NewsChannel>}
|
||||
* @example
|
||||
* if (channel.type === 'news') {
|
||||
* if (channel.type === 'GUILD_NEWS') {
|
||||
* channel.addFollower('222197033908436994', 'Important announcements')
|
||||
* .then(() => console.log('Added follower'))
|
||||
* .catch(console.error);
|
||||
|
||||
@@ -346,7 +346,7 @@ class ThreadChannel extends Channel {
|
||||
!this.archived &&
|
||||
!this.joined &&
|
||||
this.permissionsFor(this.client.user)?.has(
|
||||
this.type === 'private_thread' ? Permissions.FLAGS.MANAGE_THREADS : Permissions.FLAGS.VIEW_CHANNEL,
|
||||
this.type === 'GUILD_PRIVATE_THREAD' ? Permissions.FLAGS.MANAGE_THREADS : Permissions.FLAGS.VIEW_CHANNEL,
|
||||
false,
|
||||
)
|
||||
);
|
||||
@@ -373,7 +373,9 @@ class ThreadChannel extends Channel {
|
||||
this.permissionsFor(this.client.user)?.any(
|
||||
[
|
||||
Permissions.FLAGS.SEND_MESSAGES,
|
||||
this.type === 'private_thread' ? Permissions.FLAGS.USE_PRIVATE_THREADS : Permissions.FLAGS.USE_PUBLIC_THREADS,
|
||||
this.type === 'GUILD_PRIVATE_THREAD'
|
||||
? Permissions.FLAGS.USE_PRIVATE_THREADS
|
||||
: Permissions.FLAGS.USE_PUBLIC_THREADS,
|
||||
],
|
||||
false,
|
||||
)
|
||||
|
||||
@@ -193,7 +193,7 @@ class User extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get dmChannel() {
|
||||
return this.client.channels.cache.find(c => c.type === 'dm' && c.recipient.id === this.id) ?? null;
|
||||
return this.client.channels.cache.find(c => c.type === 'DM' && c.recipient.id === this.id) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -171,7 +171,7 @@ class VoiceState extends Base {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async setRequestToSpeak(request) {
|
||||
if (this.channel?.type !== 'stage') throw new Error('VOICE_NOT_STAGE_CHANNEL');
|
||||
if (this.channel?.type !== 'GUILD_STAGE_VOICE') throw new Error('VOICE_NOT_STAGE_CHANNEL');
|
||||
|
||||
if (this.client.user.id !== this.id) throw new Error('VOICE_STATE_NOT_OWN');
|
||||
|
||||
@@ -203,7 +203,7 @@ class VoiceState extends Base {
|
||||
async setSuppressed(suppressed) {
|
||||
if (typeof suppressed !== 'boolean') throw new TypeError('VOICE_STATE_INVALID_TYPE', 'suppressed');
|
||||
|
||||
if (this.channel?.type !== 'stage') throw new Error('VOICE_NOT_STAGE_CHANNEL');
|
||||
if (this.channel?.type !== 'GUILD_STAGE_VOICE') throw new Error('VOICE_NOT_STAGE_CHANNEL');
|
||||
|
||||
const target = this.client.user.id === this.id ? '@me' : this.id;
|
||||
|
||||
|
||||
@@ -415,31 +415,73 @@ exports.SystemMessageTypes = exports.MessageTypes.filter(
|
||||
*/
|
||||
exports.ActivityTypes = createEnum(['PLAYING', 'STREAMING', 'LISTENING', 'WATCHING', 'CUSTOM', 'COMPETING']);
|
||||
|
||||
/**
|
||||
* All available channel types:
|
||||
* * `GUILD_TEXT` - a guild text channel
|
||||
* * `DM` - a DM channel
|
||||
* * `GUILD_VOICE` - a guild voice channel
|
||||
* * `GROUP_DM` - a group DM channel
|
||||
* * `GUILD_CATEGORY` - a guild category channel
|
||||
* * `GUILD_NEWS` - a guild news channel
|
||||
* * `GUILD_STORE` - a guild store channel
|
||||
* * `GUILD_NEWS_THREAD` - a guild news channel's public thread channel
|
||||
* * `GUILD_PUBLIC_THREAD` - a guild text channel's public thread channel
|
||||
* * `GUILD_PRIVATE_THREAD` - a guild text channel's private thread channel
|
||||
* * `GUILD_STAGE_VOICE` - a guild stage voice channel
|
||||
* * `UNKNOWN` - a generic channel of unknown type, could be Channel or GuildChannel
|
||||
* @typedef {string} ChannelType
|
||||
*/
|
||||
exports.ChannelTypes = createEnum([
|
||||
'TEXT',
|
||||
'GUILD_TEXT',
|
||||
'DM',
|
||||
'VOICE',
|
||||
'GROUP',
|
||||
'CATEGORY',
|
||||
'NEWS',
|
||||
// 6
|
||||
'STORE',
|
||||
'GUILD_VOICE',
|
||||
'GROUP_DM',
|
||||
'GUILD_CATEGORY',
|
||||
'GUILD_NEWS',
|
||||
'GUILD_STORE',
|
||||
...Array(3).fill(null),
|
||||
// 10
|
||||
'NEWS_THREAD',
|
||||
'PUBLIC_THREAD',
|
||||
'PRIVATE_THREAD',
|
||||
'STAGE',
|
||||
'GUILD_NEWS_THREAD',
|
||||
'GUILD_PUBLIC_THREAD',
|
||||
'GUILD_PRIVATE_THREAD',
|
||||
'GUILD_STAGE_VOICE',
|
||||
]);
|
||||
|
||||
/**
|
||||
* The types of channels that are threads. The available types are:
|
||||
* * news_thread
|
||||
* * public_thread
|
||||
* * private_thread
|
||||
* @typedef {string} ThreadChannelType
|
||||
* The types of channels that are text-based. The available types are:
|
||||
* * DM
|
||||
* * GUILD_TEXT
|
||||
* * GUILD_NEWS
|
||||
* * GUILD_NEWS_THREAD
|
||||
* * GUILD_PUBLIC_THREAD
|
||||
* * GUILD_PRIVATE_THREAD
|
||||
* @typedef {string} TextBasedChannelTypes
|
||||
*/
|
||||
exports.ThreadChannelTypes = ['news_thread', 'public_thread', 'private_thread'];
|
||||
exports.TextBasedChannelTypes = [
|
||||
'DM',
|
||||
'GUILD_TEXT',
|
||||
'GUILD_NEWS',
|
||||
'GUILD_NEWS_THREAD',
|
||||
'GUILD_PUBLIC_THREAD',
|
||||
'GUILD_PRIVATE_THREAD',
|
||||
];
|
||||
|
||||
/**
|
||||
* The types of channels that are threads. The available types are:
|
||||
* * GUILD_NEWS_THREAD
|
||||
* * GUILD_PUBLIC_THREAD
|
||||
* * GUILD_PRIVATE_THREAD
|
||||
* @typedef {string} ThreadChannelTypes
|
||||
*/
|
||||
exports.ThreadChannelTypes = ['GUILD_NEWS_THREAD', 'GUILD_PUBLIC_THREAD', 'GUILD_PRIVATE_THREAD'];
|
||||
|
||||
/**
|
||||
* The types of channels that are voice-based. The available types are:
|
||||
* * GUILD_VOICE
|
||||
* * GUILD_STAGE_VOICE
|
||||
* @typedef {string} VoiceBasedChannelTypes
|
||||
*/
|
||||
exports.VoiceBasedChannelTypes = ['GUILD_VOICE', 'GUILD_STAGE_VOICE'];
|
||||
|
||||
exports.ClientApplicationAssetTypes = {
|
||||
SMALL: 1,
|
||||
|
||||
@@ -582,7 +582,7 @@ class Util extends null {
|
||||
str = str
|
||||
.replace(/<@!?[0-9]+>/g, input => {
|
||||
const id = input.replace(/<|!|>|@/g, '');
|
||||
if (channel.type === 'dm') {
|
||||
if (channel.type === 'DM') {
|
||||
const user = channel.client.users.cache.get(id);
|
||||
return user ? Util.removeMentions(`@${user.username}`) : input;
|
||||
}
|
||||
@@ -600,7 +600,7 @@ class Util extends null {
|
||||
return mentionedChannel ? `#${mentionedChannel.name}` : input;
|
||||
})
|
||||
.replace(/<@&[0-9]+>/g, input => {
|
||||
if (channel.type === 'dm') return input;
|
||||
if (channel.type === 'DM') return input;
|
||||
const role = channel.guild.roles.cache.get(input.replace(/<|@|>|&/g, ''));
|
||||
return role ? `@${role.name}` : input;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user