feat(NewsChannel): add support for following (#4805)

Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
This commit is contained in:
Jan
2020-09-25 23:45:47 +02:00
committed by GitHub
parent f2bbad36d5
commit f83b3d7fc1
2 changed files with 21 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
'use strict';
const TextChannel = require('./TextChannel');
const { Error } = require('../errors');
/**
* Represents a guild news channel on Discord.
@@ -13,6 +14,25 @@ class NewsChannel extends TextChannel {
// News channels don't have a rate limit per user, remove it
this.rateLimitPerUser = undefined;
}
/**
* Adds the target to this channel's followers.
* @param {GuildChannelResolvable} channel The channel where the webhook should be created
* @param {string} [reason] Reason for creating the webhook
* @returns {Promise<NewsChannel>}
* @example
* if (channel.type === 'news') {
* channel.addFollower('222197033908436994', 'Important announcements')
* .then(() => console.log('Added follower'))
* .catch(console.error);
* }
*/
async addFollower(channel, reason) {
const channelID = this.guild.channels.resolveID(channel);
if (!channelID) throw new Error('GUILD_CHANNEL_RESOLVE');
await this.client.api.channels(this.id).followers.post({ data: { webhook_channel_id: channelID }, reason });
return this;
}
}
module.exports = NewsChannel;

1
typings/index.d.ts vendored
View File

@@ -1187,6 +1187,7 @@ declare module 'discord.js' {
): Promise<Webhook>;
public setNSFW(nsfw: boolean, reason?: string): Promise<NewsChannel>;
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
public addFollower(channel: GuildChannelResolvable, reason?: string): Promise<NewsChannel>;
}
export class PartialGroupDMChannel extends Channel {