From 23d59d70ea31bbc03af9b158909794a6e3af4d47 Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Tue, 21 Feb 2023 14:25:40 +0700 Subject: [PATCH] feat v13: add `addFollower` on GuildChannelManager #9050 djs --- 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 1dc748a..85db817 100644 --- a/src/managers/GuildChannelManager.js +++ b/src/managers/GuildChannelManager.js @@ -228,6 +228,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 e2ef0a8..f8d4aae 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 4a65dca..885af82 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3913,6 +3913,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(