diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index 3dfa0839d..2a2f91248 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -6,6 +6,7 @@ const PermissionOverwrites = require('./PermissionOverwrites'); const Role = require('./Role'); const { Error, TypeError } = require('../errors'); const Collection = require('../util/Collection'); +const { ChannelTypes } = require('../util/Constants'); const Permissions = require('../util/Permissions'); const Util = require('../util/Util'); @@ -294,6 +295,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 {number} [position] The position of the channel * @property {string} [topic] The topic of the text channel * @property {boolean} [nsfw] Whether the channel is NSFW @@ -355,6 +357,7 @@ class GuildChannel extends Channel { const newData = await this.client.api.channels(this.id).patch({ data: { name: (data.name || this.name).trim(), + type: data.type ? ChannelTypes[data.type.toUpperCase()] : this.type, topic: data.topic, nsfw: data.nsfw, bitrate: data.bitrate || this.bitrate, @@ -367,9 +370,7 @@ class GuildChannel extends Channel { reason, }); - const clone = this._clone(); - clone._patch(newData); - return clone; + return this.client.actions.ChannelUpdate.handle(newData).updated; } /** diff --git a/src/structures/TextChannel.js b/src/structures/TextChannel.js index b92e0c7e6..4d544075c 100644 --- a/src/structures/TextChannel.js +++ b/src/structures/TextChannel.js @@ -86,6 +86,16 @@ class TextChannel extends GuildChannel { return this.edit({ nsfw }, reason); } + /** + * Sets the type of this channel (only conversion between text and news is supported) + * @param {string} type The new channel type + * @param {string} [reason] Reason for changing the channel's type + * @returns {Promise} + */ + setType(type, reason) { + return this.edit({ type }, reason); + } + /** * Fetches all webhooks for the channel. * @returns {Promise>} diff --git a/typings/index.d.ts b/typings/index.d.ts index d446d99ac..f67831e51 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1162,6 +1162,7 @@ declare module 'discord.js' { options?: { avatar?: BufferResolvable | Base64Resolvable; reason?: string }, ): Promise; public setNSFW(nsfw: boolean, reason?: string): Promise; + public setType(type: Pick, reason?: string): Promise; public fetchWebhooks(): Promise>; public addFollower(channel: GuildChannelResolvable, reason?: string): Promise; } @@ -1513,6 +1514,7 @@ declare module 'discord.js' { ): Promise; public setNSFW(nsfw: boolean, reason?: string): Promise; public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise; + public setType(type: Pick, reason?: string): Promise; public fetchWebhooks(): Promise>; } @@ -2339,6 +2341,7 @@ declare module 'discord.js' { interface ChannelData { name?: string; + type?: Pick; position?: number; topic?: string; nsfw?: boolean;