diff --git a/src/structures/NewsChannel.js b/src/structures/NewsChannel.js index 76727fcdd..331971901 100644 --- a/src/structures/NewsChannel.js +++ b/src/structures/NewsChannel.js @@ -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} + * @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; diff --git a/typings/index.d.ts b/typings/index.d.ts index 23031d825..381686ccc 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1187,6 +1187,7 @@ declare module 'discord.js' { ): Promise; public setNSFW(nsfw: boolean, reason?: string): Promise; public fetchWebhooks(): Promise>; + public addFollower(channel: GuildChannelResolvable, reason?: string): Promise; } export class PartialGroupDMChannel extends Channel {