From caeb1cbfdb2f2f007252c4d7e9f47a575c24bcb5 Mon Sep 17 00:00:00 2001 From: Synbulat Biishev Date: Sun, 16 Oct 2022 19:04:30 +0300 Subject: [PATCH] feat(GuildChannelManager): add `.addFollower()` method (#8567) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(GuildChannelManager): add `.addFollower()` method * docs: dpply suggestions Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * fix: resolve from `GuildChannelManager` Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * types: correct channel type * docs: update description Co-authored-by: A. Román * docs: update description Co-authored-by: A. Román Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: A. Román Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/managers/GuildChannelManager.js | 18 ++++++++++++++++++ packages/discord.js/typings/index.d.ts | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/packages/discord.js/src/managers/GuildChannelManager.js b/packages/discord.js/src/managers/GuildChannelManager.js index 22358885ee22..81974c01a201 100644 --- a/packages/discord.js/src/managers/GuildChannelManager.js +++ b/packages/discord.js/src/managers/GuildChannelManager.js @@ -98,6 +98,24 @@ class GuildChannelManager extends CachedManager { return super.resolveId(channel); } + /** + * 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(ErrorCodes.GuildChannelResolve); + const { webhook_id } = await this.client.rest.post(Routes.channelFollowers(channelId), { + body: { webhook_channel_id: targetChannelId }, + reason, + }); + return webhook_id; + } + /** * Options used to create a new channel in a guild. * @typedef {CategoryCreateChannelOptions} GuildChannelCreateOptions diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 9798eb0028a7..e2586331a58d 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -3457,6 +3457,11 @@ export class GuildChannelManager extends CachedManager; public create( options: GuildChannelCreateOptions & { type: T }, ): Promise;