mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13: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;
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ client.on('ready', async () => {
|
||||
try {
|
||||
const guild = await client.guilds.create('testing', {
|
||||
channels: [
|
||||
{ name: 'afk channel', type: 'voice', id: 0 },
|
||||
{ name: 'afk channel', type: 'GUILD_VOICE', id: 0 },
|
||||
{ name: 'system-channel', id: 1 },
|
||||
],
|
||||
afkChannelId: 0,
|
||||
|
||||
@@ -46,7 +46,7 @@ client.on('messageCreate', message => {
|
||||
if (true) {
|
||||
if (message.content === 'makechann') {
|
||||
if (message.channel.guild) {
|
||||
message.channel.guild.channels.create('hi', { type: 'text' }).then(console.log);
|
||||
message.channel.guild.channels.create('hi', { type: 'GUILD_TEXT' }).then(console.log);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
36
typings/enums.d.ts
vendored
36
typings/enums.d.ts
vendored
@@ -27,33 +27,19 @@ export enum ApplicationCommandPermissionTypes {
|
||||
USER = 2,
|
||||
}
|
||||
|
||||
export enum ChannelType {
|
||||
text = 0,
|
||||
dm = 1,
|
||||
voice = 2,
|
||||
group = 3,
|
||||
category = 4,
|
||||
news = 5,
|
||||
store = 6,
|
||||
unknown = 7,
|
||||
news_thread = 10,
|
||||
public_thread = 11,
|
||||
private_thread = 12,
|
||||
stage = 13,
|
||||
}
|
||||
|
||||
export enum ChannelTypes {
|
||||
TEXT = 0,
|
||||
GUILD_TEXT = 0,
|
||||
DM = 1,
|
||||
VOICE = 2,
|
||||
GROUP = 3,
|
||||
CATEGORY = 4,
|
||||
NEWS = 5,
|
||||
STORE = 6,
|
||||
NEWS_THREAD = 10,
|
||||
PUBLIC_THREAD = 11,
|
||||
PRIVATE_THREAD = 12,
|
||||
STAGE = 13,
|
||||
GUILD_VOICE = 2,
|
||||
GROUP_DM = 3,
|
||||
GUILD_CATEGORY = 4,
|
||||
GUILD_NEWS = 5,
|
||||
GUILD_STORE = 6,
|
||||
UNKNOWN = 7,
|
||||
GUILD_NEWS_THREAD = 10,
|
||||
GUILD_PUBLIC_THREAD = 11,
|
||||
GUILD_PRIVATE_THREAD = 12,
|
||||
GUILD_STAGE_VOICE = 13,
|
||||
}
|
||||
|
||||
export enum DefaultMessageNotificationLevels {
|
||||
|
||||
93
typings/index.d.ts
vendored
93
typings/index.d.ts
vendored
@@ -37,7 +37,6 @@ import {
|
||||
ActivityTypes,
|
||||
ApplicationCommandOptionTypes,
|
||||
ApplicationCommandPermissionTypes,
|
||||
ChannelType,
|
||||
ChannelTypes,
|
||||
ConstantsClientApplicationAssetTypes,
|
||||
ConstantsColors,
|
||||
@@ -259,7 +258,7 @@ export class ButtonInteraction extends MessageComponentInteraction {
|
||||
|
||||
export class CategoryChannel extends GuildChannel {
|
||||
public readonly children: Collection<Snowflake, GuildChannel>;
|
||||
public type: 'category';
|
||||
public type: 'GUILD_CATEGORY';
|
||||
}
|
||||
|
||||
export type CategoryChannelResolvable = Snowflake | CategoryChannel;
|
||||
@@ -270,7 +269,7 @@ export class Channel extends Base {
|
||||
public readonly createdTimestamp: number;
|
||||
public deleted: boolean;
|
||||
public id: Snowflake;
|
||||
public type: keyof typeof ChannelType;
|
||||
public type: keyof typeof ChannelTypes;
|
||||
public delete(): Promise<Channel>;
|
||||
public fetch(force?: boolean): Promise<Channel>;
|
||||
public isText(): this is TextChannel | DMChannel | NewsChannel | ThreadChannel;
|
||||
@@ -458,7 +457,7 @@ export class DMChannel extends TextBasedChannel(Channel, ['bulkDelete']) {
|
||||
public messages: MessageManager;
|
||||
public recipient: User;
|
||||
public readonly partial: false;
|
||||
public type: 'dm';
|
||||
public type: 'DM';
|
||||
public fetch(force?: boolean): Promise<this>;
|
||||
}
|
||||
|
||||
@@ -646,7 +645,7 @@ export class GuildChannel extends Channel {
|
||||
public readonly permissionsLocked: boolean | null;
|
||||
public readonly position: number;
|
||||
public rawPosition: number;
|
||||
public type: Exclude<keyof typeof ChannelType, 'dm' | 'group' | 'unknown'>;
|
||||
public type: Exclude<keyof typeof ChannelTypes, 'DM' | 'GROUP_DM' | 'UNKNOWN'>;
|
||||
public readonly viewable: boolean;
|
||||
public clone(options?: GuildChannelCloneOptions): Promise<this>;
|
||||
public createInvite(options?: CreateInviteOptions): Promise<Invite>;
|
||||
@@ -1229,14 +1228,14 @@ export class NewsChannel extends TextBasedChannel(GuildChannel) {
|
||||
public nsfw: boolean;
|
||||
public threads: ThreadManager<AllowedThreadTypeForNewsChannel>;
|
||||
public topic: string | null;
|
||||
public type: 'news';
|
||||
public type: 'GUILD_NEWS';
|
||||
public createWebhook(name: string, options?: ChannelWebhookCreateOptions): Promise<Webhook>;
|
||||
public setDefaultAutoArchiveDuration(
|
||||
defaultAutoArchiveDuration: ThreadAutoArchiveDuration,
|
||||
reason?: string,
|
||||
): Promise<NewsChannel>;
|
||||
public setNSFW(nsfw: boolean, reason?: string): Promise<NewsChannel>;
|
||||
public setType(type: Pick<typeof ChannelType, 'text' | 'news'>, reason?: string): Promise<GuildChannel>;
|
||||
public setType(type: Pick<typeof ChannelTypes, 'GUILD_TEXT' | 'GUILD_NEWS'>, reason?: string): Promise<GuildChannel>;
|
||||
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
|
||||
public addFollower(channel: GuildChannelResolvable, reason?: string): Promise<NewsChannel>;
|
||||
}
|
||||
@@ -1492,7 +1491,7 @@ export class SnowflakeUtil extends null {
|
||||
|
||||
export class StageChannel extends BaseGuildVoiceChannel {
|
||||
public topic: string | null;
|
||||
public type: 'stage';
|
||||
public type: 'GUILD_STAGE_VOICE';
|
||||
public readonly stageInstance: StageInstance | null;
|
||||
public createStageInstance(options: StageInstanceCreateOptions): Promise<StageInstance>;
|
||||
}
|
||||
@@ -1532,7 +1531,7 @@ export class Sticker extends Base {
|
||||
export class StoreChannel extends GuildChannel {
|
||||
public constructor(guild: Guild, data?: unknown, client?: Client);
|
||||
public nsfw: boolean;
|
||||
public type: 'store';
|
||||
public type: 'GUILD_STORE';
|
||||
}
|
||||
|
||||
export class SystemChannelFlags extends BitField<SystemChannelFlagsString> {
|
||||
@@ -1573,7 +1572,7 @@ export class TextChannel extends TextBasedChannel(GuildChannel) {
|
||||
public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
|
||||
public messages: MessageManager;
|
||||
public nsfw: boolean;
|
||||
public type: 'text';
|
||||
public type: 'GUILD_TEXT';
|
||||
public rateLimitPerUser: number;
|
||||
public threads: ThreadManager<AllowedThreadTypeForTextChannel>;
|
||||
public topic: string | null;
|
||||
@@ -1584,7 +1583,7 @@ export class TextChannel extends TextBasedChannel(GuildChannel) {
|
||||
): Promise<TextChannel>;
|
||||
public setNSFW(nsfw: boolean, reason?: string): Promise<TextChannel>;
|
||||
public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<TextChannel>;
|
||||
public setType(type: Pick<typeof ChannelType, 'text' | 'news'>, reason?: string): Promise<GuildChannel>;
|
||||
public setType(type: Pick<typeof ChannelTypes, 'GUILD_TEXT' | 'GUILD_NEWS'>, reason?: string): Promise<GuildChannel>;
|
||||
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
|
||||
}
|
||||
|
||||
@@ -1612,7 +1611,7 @@ export class ThreadChannel extends TextBasedChannel(Channel) {
|
||||
public readonly parent: TextChannel | NewsChannel | null;
|
||||
public parentId: Snowflake;
|
||||
public rateLimitPerUser: number;
|
||||
public type: ThreadChannelType;
|
||||
public type: ThreadChannelTypes;
|
||||
public readonly unarchivable: boolean;
|
||||
public delete(reason?: string): Promise<ThreadChannel>;
|
||||
public edit(data: ThreadEditData, reason?: string): Promise<ThreadChannel>;
|
||||
@@ -1742,7 +1741,7 @@ export class Formatters extends null {
|
||||
export class VoiceChannel extends BaseGuildVoiceChannel {
|
||||
public readonly editable: boolean;
|
||||
public readonly speakable: boolean;
|
||||
public type: 'voice';
|
||||
public type: 'GUILD_VOICE';
|
||||
public setBitrate(bitrate: number, reason?: string): Promise<VoiceChannel>;
|
||||
public setUserLimit(userLimit: number, reason?: string): Promise<VoiceChannel>;
|
||||
}
|
||||
@@ -2005,7 +2004,9 @@ export const Constants: {
|
||||
Opcodes: typeof ConstantsOpcodes;
|
||||
APIErrors: APIErrors;
|
||||
ChannelTypes: typeof ChannelTypes;
|
||||
ThreadChannelTypes: ThreadChannelType[];
|
||||
ThreadChannelTypes: ThreadChannelTypes[];
|
||||
TextBasedChannelTypes: TextBasedChannelTypes[];
|
||||
VoiceBasedChannelTypes: VoiceBasedChannelTypes[];
|
||||
ClientApplicationAssetTypes: typeof ConstantsClientApplicationAssetTypes;
|
||||
InviteScopes: InviteScope[];
|
||||
MessageTypes: MessageType[];
|
||||
@@ -2168,12 +2169,18 @@ export class GuildChannelManager extends CachedManager<
|
||||
public constructor(guild: Guild, iterable?: Iterable<unknown>);
|
||||
public readonly channelCountWithoutThreads: number;
|
||||
public guild: Guild;
|
||||
public create(name: string, options: GuildChannelCreateOptions & { type: 'voice' }): Promise<VoiceChannel>;
|
||||
public create(name: string, options: GuildChannelCreateOptions & { type: 'category' }): Promise<CategoryChannel>;
|
||||
public create(name: string, options?: GuildChannelCreateOptions & { type?: 'text' }): Promise<TextChannel>;
|
||||
public create(name: string, options: GuildChannelCreateOptions & { type: 'news' }): Promise<NewsChannel>;
|
||||
public create(name: string, options: GuildChannelCreateOptions & { type: 'store' }): Promise<StoreChannel>;
|
||||
public create(name: string, options: GuildChannelCreateOptions & { type: 'stage' }): Promise<StageChannel>;
|
||||
public create(name: string, options: GuildChannelCreateOptions & { type: 'GUILD_VOICE' }): Promise<VoiceChannel>;
|
||||
public create(
|
||||
name: string,
|
||||
options: GuildChannelCreateOptions & { type: 'GUILD_CATEGORY' },
|
||||
): Promise<CategoryChannel>;
|
||||
public create(name: string, options?: GuildChannelCreateOptions & { type?: 'GUILD_TEXT' }): Promise<TextChannel>;
|
||||
public create(name: string, options: GuildChannelCreateOptions & { type: 'GUILD_NEWS' }): Promise<NewsChannel>;
|
||||
public create(name: string, options: GuildChannelCreateOptions & { type: 'GUILD_STORE' }): Promise<StoreChannel>;
|
||||
public create(
|
||||
name: string,
|
||||
options: GuildChannelCreateOptions & { type: 'GUILD_STAGE_VOICE' },
|
||||
): Promise<StageChannel>;
|
||||
public create(
|
||||
name: string,
|
||||
options: GuildChannelCreateOptions,
|
||||
@@ -2486,9 +2493,9 @@ export interface AddGuildMemberOptions {
|
||||
|
||||
export type AllowedImageFormat = 'webp' | 'png' | 'jpg' | 'jpeg' | 'gif';
|
||||
|
||||
export type AllowedThreadTypeForNewsChannel = 'news_thread' | 10;
|
||||
export type AllowedThreadTypeForNewsChannel = 'GUILD_NEWS_THREAD' | 10;
|
||||
|
||||
export type AllowedThreadTypeForTextChannel = 'public_thread' | 'private_thread' | 11 | 12;
|
||||
export type AllowedThreadTypeForTextChannel = 'GUILD_PUBLIC_THREAD' | 'GUILD_PRIVATE_THREAD' | 11 | 12;
|
||||
|
||||
export interface APIErrors {
|
||||
UNKNOWN_ACCOUNT: 10001;
|
||||
@@ -2727,7 +2734,7 @@ export interface ChannelCreationOverwrites {
|
||||
|
||||
export interface ChannelData {
|
||||
name?: string;
|
||||
type?: Pick<typeof ChannelType, 'text' | 'news'>;
|
||||
type?: Pick<typeof ChannelTypes, 'GUILD_TEXT' | 'GUILD_NEWS'>;
|
||||
position?: number;
|
||||
topic?: string;
|
||||
nsfw?: boolean;
|
||||
@@ -2957,7 +2964,7 @@ export interface StageInstanceCreateOptions {
|
||||
export interface CrosspostedChannel {
|
||||
channelId: Snowflake;
|
||||
guildId: Snowflake;
|
||||
type: keyof typeof ChannelType;
|
||||
type: keyof typeof ChannelTypes;
|
||||
name: string;
|
||||
}
|
||||
|
||||
@@ -3182,17 +3189,17 @@ export interface GuildChannelCreateOptions {
|
||||
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
|
||||
topic?: string;
|
||||
type?: Exclude<
|
||||
keyof typeof ChannelType | ChannelType,
|
||||
| 'dm'
|
||||
| 'group'
|
||||
| 'unknown'
|
||||
| 'public_thread'
|
||||
| 'private_thread'
|
||||
| ChannelType.dm
|
||||
| ChannelType.group
|
||||
| ChannelType.unknown
|
||||
| ChannelType.public_thread
|
||||
| ChannelType.private_thread
|
||||
keyof typeof ChannelTypes | ChannelTypes,
|
||||
| 'DM'
|
||||
| 'GROUP_DM'
|
||||
| 'UNKNOWN'
|
||||
| 'GUILD_PUBLIC_THREAD'
|
||||
| 'GUILD_PRIVATE_THREAD'
|
||||
| ChannelTypes.DM
|
||||
| ChannelTypes.GROUP_DM
|
||||
| ChannelTypes.UNKNOWN
|
||||
| ChannelTypes.GUILD_PUBLIC_THREAD
|
||||
| ChannelTypes.GUILD_PRIVATE_THREAD
|
||||
>;
|
||||
nsfw?: boolean;
|
||||
parent?: ChannelResolvable;
|
||||
@@ -3807,7 +3814,7 @@ export interface PartialDMChannel
|
||||
lastMessageId: undefined;
|
||||
messages: MessageManager;
|
||||
recipient: User | PartialUser;
|
||||
type: 'dm';
|
||||
type: 'DM';
|
||||
readonly typing: boolean;
|
||||
readonly typingCount: number;
|
||||
}
|
||||
@@ -3816,7 +3823,7 @@ export interface PartialChannelData {
|
||||
id?: Snowflake | number;
|
||||
name: string;
|
||||
topic?: string;
|
||||
type?: ChannelType;
|
||||
type?: ChannelTypes;
|
||||
parentId?: Snowflake | number;
|
||||
permissionOverwrites?: PartialOverwriteData[];
|
||||
}
|
||||
@@ -4033,11 +4040,19 @@ export interface StageInstanceEditOptions {
|
||||
privacyLevel?: PrivacyLevel | number;
|
||||
}
|
||||
|
||||
export type TextBasedChannelTypes =
|
||||
| 'DM'
|
||||
| 'GUILD_TEXT'
|
||||
| 'GUILD_NEWS'
|
||||
| 'GUILD_NEWS_THREAD'
|
||||
| 'GUILD_PUBLIC_THREAD'
|
||||
| 'GUILD_PRIVATE_THREAD';
|
||||
|
||||
export type ThreadAutoArchiveDuration = 60 | 1440 | 4320 | 10080;
|
||||
|
||||
export type ThreadChannelResolvable = ThreadChannel | Snowflake;
|
||||
|
||||
export type ThreadChannelType = 'news_thread' | 'public_thread' | 'private_thread';
|
||||
export type ThreadChannelTypes = 'GUILD_NEWS_THREAD' | 'GUILD_PUBLIC_THREAD' | 'GUILD_PRIVATE_THREAD';
|
||||
|
||||
export interface ThreadCreateOptions<AllowedThreadType> {
|
||||
name: string;
|
||||
@@ -4085,6 +4100,8 @@ export interface Vanity {
|
||||
|
||||
export type VerificationLevel = keyof typeof VerificationLevels;
|
||||
|
||||
export type VoiceBasedChannelTypes = 'GUILD_VOICE' | 'GUILD_STAGE_VOICE';
|
||||
|
||||
export type WebhookClientOptions = Pick<
|
||||
ClientOptions,
|
||||
'allowedMentions' | 'restTimeOffset' | 'restRequestTimeout' | 'retryLimit' | 'http'
|
||||
|
||||
Reference in New Issue
Block a user