Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(GuildChannel): support conversion between text and news #5022

Merged
merged 9 commits into from
Jan 22, 2021
7 changes: 4 additions & 3 deletions src/structures/GuildChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/structures/TextChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
monbrey marked this conversation as resolved.
Show resolved Hide resolved
* @returns {Promise<GuildChannel>}
*/
setType(type, reason) {
return this.edit({ type }, reason);
}

/**
* Fetches all webhooks for the channel.
* @returns {Promise<Collection<Snowflake, Webhook>>}
Expand Down
3 changes: 3 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,7 @@ declare module 'discord.js' {
options?: { avatar?: BufferResolvable | Base64Resolvable; reason?: string },
): Promise<Webhook>;
public setNSFW(nsfw: boolean, reason?: string): Promise<NewsChannel>;
public setType(type: string, reason?: string): Promise<GuildChannel>;
iCrawl marked this conversation as resolved.
Show resolved Hide resolved
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
public addFollower(channel: GuildChannelResolvable, reason?: string): Promise<NewsChannel>;
}
Expand Down Expand Up @@ -1529,6 +1530,7 @@ declare module 'discord.js' {
): Promise<Webhook>;
public setNSFW(nsfw: boolean, reason?: string): Promise<TextChannel>;
public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<TextChannel>;
public setType(type: string, reason?: string): Promise<GuildChannel>;
iCrawl marked this conversation as resolved.
Show resolved Hide resolved
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
}

Expand Down Expand Up @@ -2230,6 +2232,7 @@ declare module 'discord.js' {

interface ChannelData {
name?: string;
type?: string;
monbrey marked this conversation as resolved.
Show resolved Hide resolved
position?: number;
topic?: string;
nsfw?: boolean;
Expand Down