From b01f4147d4f3bca021bc269c9f06463f06e3db53 Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> Date: Thu, 14 Apr 2022 06:49:33 -0400 Subject: [PATCH] feat: add guild directory support (#6788) --- packages/discord.js/package.json | 2 +- packages/discord.js/src/structures/Channel.js | 13 +++++++++++++ .../src/structures/DirectoryChannel.js | 19 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 5 +++++ yarn.lock | 10 +++++----- 5 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 packages/discord.js/src/structures/DirectoryChannel.js diff --git a/packages/discord.js/package.json b/packages/discord.js/package.json index 8c8133dca..d3964ddcc 100644 --- a/packages/discord.js/package.json +++ b/packages/discord.js/package.json @@ -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", diff --git a/packages/discord.js/src/structures/Channel.js b/packages/discord.js/src/structures/Channel.js index ff2277c80..a47ffb233 100644 --- a/packages/discord.js/src/structures/Channel.js +++ b/packages/discord.js/src/structures/Channel.js @@ -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); } diff --git a/packages/discord.js/src/structures/DirectoryChannel.js b/packages/discord.js/src/structures/DirectoryChannel.js new file mode 100644 index 000000000..faf2e3d04 --- /dev/null +++ b/packages/discord.js/src/structures/DirectoryChannel.js @@ -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; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index ce9c97ba4..9c8418dbb 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -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; } +export class DirectoryChannel extends Channel {} + export class StageInstance extends Base { private constructor(client: Client, data: RawStageInstanceData, channel: StageChannel); public id: Snowflake; diff --git a/yarn.lock b/yarn.lock index 3f416cb79..55ba25078 100644 --- a/yarn.lock +++ b/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