mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat: add guild directory support (#6788)
This commit is contained in:
@@ -52,7 +52,7 @@
|
||||
"@discordjs/rest": "workspace:^",
|
||||
"@sapphire/snowflake": "^3.1.0",
|
||||
"@types/ws": "^8.2.2",
|
||||
"discord-api-types": "^0.31.0",
|
||||
"discord-api-types": "^0.31.1",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"lodash.snakecase": "^4.1.1",
|
||||
"undici": "^4.14.1",
|
||||
|
||||
@@ -11,6 +11,7 @@ let StageChannel;
|
||||
let TextChannel;
|
||||
let ThreadChannel;
|
||||
let VoiceChannel;
|
||||
let DirectoryChannel;
|
||||
|
||||
/**
|
||||
* Represents any channel on Discord.
|
||||
@@ -173,6 +174,14 @@ class Channel extends Base {
|
||||
return this.type === ChannelType.GuildStageVoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this channel is a {@link DirectoryChannel}
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isDirectory() {
|
||||
return this.type === ChannelType.GuildDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this channel is {@link TextBasedChannels text-based}.
|
||||
* @returns {boolean}
|
||||
@@ -205,6 +214,7 @@ class Channel extends Base {
|
||||
TextChannel ??= require('./TextChannel');
|
||||
ThreadChannel ??= require('./ThreadChannel');
|
||||
VoiceChannel ??= require('./VoiceChannel');
|
||||
DirectoryChannel ??= require('./DirectoryChannel');
|
||||
|
||||
let channel;
|
||||
if (!data.guild_id && !guild) {
|
||||
@@ -246,6 +256,9 @@ class Channel extends Base {
|
||||
if (!allowUnknownGuild) channel.parent?.threads.cache.set(channel.id, channel);
|
||||
break;
|
||||
}
|
||||
case ChannelType.GuildDirectory:
|
||||
channel = new DirectoryChannel(client, data);
|
||||
break;
|
||||
}
|
||||
if (channel && !allowUnknownGuild) guild.channels?.cache.set(channel.id, channel);
|
||||
}
|
||||
|
||||
19
packages/discord.js/src/structures/DirectoryChannel.js
Normal file
19
packages/discord.js/src/structures/DirectoryChannel.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const { Channel } = require('./Channel');
|
||||
|
||||
/**
|
||||
* Represents a channel that displays a directory of guilds
|
||||
*/
|
||||
class DirectoryChannel extends Channel {
|
||||
_patch(data) {
|
||||
super._patch(data);
|
||||
/**
|
||||
* The channel's name
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = data.name;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DirectoryChannel;
|
||||
5
packages/discord.js/typings/index.d.ts
vendored
5
packages/discord.js/typings/index.d.ts
vendored
@@ -682,6 +682,7 @@ export interface MappedChannelCategoryTypes {
|
||||
[ChannelType.GuildVoice]: VoiceChannel;
|
||||
[ChannelType.GuildText]: TextChannel;
|
||||
[ChannelType.GuildStageVoice]: StageChannel;
|
||||
[ChannelType.GuildForum]: never; // TODO: Fix when guild forums come out
|
||||
}
|
||||
|
||||
export type CategoryChannelType = Exclude<
|
||||
@@ -692,6 +693,7 @@ export type CategoryChannelType = Exclude<
|
||||
| ChannelType.GuildNewsThread
|
||||
| ChannelType.GuildPrivateThread
|
||||
| ChannelType.GuildCategory
|
||||
| ChannelType.GuildDirectory
|
||||
>;
|
||||
|
||||
export class CategoryChannel extends GuildChannel {
|
||||
@@ -719,6 +721,7 @@ export abstract class Channel extends Base {
|
||||
public isNews(): this is NewsChannel;
|
||||
public isThread(): this is ThreadChannel;
|
||||
public isStage(): this is StageChannel;
|
||||
public isDirectory(): this is DirectoryChannel;
|
||||
public isTextBased(): this is TextBasedChannel;
|
||||
public isDMBased(): this is PartialGroupDMChannel | DMChannel | PartialDMChannel;
|
||||
public isVoiceBased(): this is VoiceBasedChannel;
|
||||
@@ -2218,6 +2221,8 @@ export class StageChannel extends BaseGuildVoiceChannel {
|
||||
public setTopic(topic: string): Promise<StageChannel>;
|
||||
}
|
||||
|
||||
export class DirectoryChannel extends Channel {}
|
||||
|
||||
export class StageInstance extends Base {
|
||||
private constructor(client: Client, data: RawStageInstanceData, channel: StageChannel);
|
||||
public id: Snowflake;
|
||||
|
||||
10
yarn.lock
10
yarn.lock
@@ -4429,10 +4429,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"discord-api-types@npm:^0.31.0":
|
||||
version: 0.31.0
|
||||
resolution: "discord-api-types@npm:0.31.0"
|
||||
checksum: 7ac466df8f3b62ebfa18296ef8cbf7a35ae295b775184b01f4357409cff89aa4e85a67e7fb3363b4a4ff796ff7313865e0266706b3d7908ef2238147a196a806
|
||||
"discord-api-types@npm:^0.31.1":
|
||||
version: 0.31.1
|
||||
resolution: "discord-api-types@npm:0.31.1"
|
||||
checksum: 5a18e512b549b75d55892b0dbc2dc7c46526bee0d001b73d41d144f4653de847c96b9c57342a32479af738f46acd80ee21686dced9fe0184dcac86b669b31f18
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -4447,7 +4447,7 @@ __metadata:
|
||||
"@sapphire/snowflake": ^3.1.0
|
||||
"@types/node": ^16.11.24
|
||||
"@types/ws": ^8.2.2
|
||||
discord-api-types: ^0.31.0
|
||||
discord-api-types: ^0.31.1
|
||||
dtslint: ^4.2.1
|
||||
eslint: ^8.9.0
|
||||
eslint-config-prettier: ^8.3.0
|
||||
|
||||
Reference in New Issue
Block a user