From 86329ad66fb5055c49893e69bff4c6ba2d412d29 Mon Sep 17 00:00:00 2001 From: Jaworek Date: Fri, 17 Feb 2023 22:47:13 +0100 Subject: [PATCH] feat(GuildChannelManager): add `addFollower` (#9050) * feat: addFolower method * Update src/structures/NewsChannel.js Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- src/managers/GuildChannelManager.js | 18 ++++++++++++++++++ src/structures/NewsChannel.js | 1 + typings/index.d.ts | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/src/managers/GuildChannelManager.js b/src/managers/GuildChannelManager.js index 0b4ad0def..4deae2c28 100644 --- a/src/managers/GuildChannelManager.js +++ b/src/managers/GuildChannelManager.js @@ -229,6 +229,24 @@ class GuildChannelManager extends CachedManager { return new Webhook(this.client, data); } + /** + * Adds the target channel to a channel's followers. + * @param {NewsChannel|Snowflake} channel The channel to follow + * @param {TextChannelResolvable} targetChannel The channel where published announcements will be posted at + * @param {string} [reason] Reason for creating the webhook + * @returns {Promise} Returns created target webhook id. + */ + async addFollower(channel, targetChannel, reason) { + const channelId = this.resolveId(channel); + const targetChannelId = this.resolveId(targetChannel); + if (!channelId || !targetChannelId) throw new Error('GUILD_CHANNEL_RESOLVE'); + const { webhook_id } = await this.client.api.channels[channelId].followers.post({ + data: { webhook_channel_id: targetChannelId }, + reason, + }); + return webhook_id; + } + /** * The data for a guild channel. * @typedef {Object} ChannelData diff --git a/src/structures/NewsChannel.js b/src/structures/NewsChannel.js index e2ef0a87c..f8d4aae43 100644 --- a/src/structures/NewsChannel.js +++ b/src/structures/NewsChannel.js @@ -10,6 +10,7 @@ const { Error } = require('../errors'); class NewsChannel extends BaseGuildTextChannel { /** * Adds the target to this channel's followers. + * If you need the created webhook id, use {@link GuildChannelManager#addFollower}. * @param {TextChannelResolvable} channel The channel where the webhook should be created * @param {string} [reason] Reason for creating the webhook * @returns {Promise} diff --git a/typings/index.d.ts b/typings/index.d.ts index c1eb3ba7f..c5583f0ed 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3356,6 +3356,11 @@ export class GuildChannelManager extends CachedManager; + public addFollower( + channel: NewsChannel | Snowflake, + targetChannel: TextChannelResolvable, + reason?: string, + ): Promise; public edit(channel: GuildChannelResolvable, data: ChannelData, reason?: string): Promise; public fetch(id: Snowflake, options?: BaseFetchOptions): Promise; public fetch(