feat v13: add addFollower on GuildChannelManager

#9050 djs
This commit is contained in:
Elysia 2023-02-21 14:25:40 +07:00
parent fae7c596d1
commit 23d59d70ea
3 changed files with 24 additions and 0 deletions

View File

@ -228,6 +228,24 @@ class GuildChannelManager extends CachedManager {
return new Webhook(this.client, data); 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<Snowflake>} 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. * The data for a guild channel.
* @typedef {Object} ChannelData * @typedef {Object} ChannelData

View File

@ -10,6 +10,7 @@ const { Error } = require('../errors');
class NewsChannel extends BaseGuildTextChannel { class NewsChannel extends BaseGuildTextChannel {
/** /**
* Adds the target to this channel's followers. * Adds the target to this channel's followers.
* <info>If you need the created webhook id, use {@link GuildChannelManager#addFollower}.</info>
* @param {TextChannelResolvable} channel The channel where the webhook should be created * @param {TextChannelResolvable} channel The channel where the webhook should be created
* @param {string} [reason] Reason for creating the webhook * @param {string} [reason] Reason for creating the webhook
* @returns {Promise<NewsChannel>} * @returns {Promise<NewsChannel>}

5
typings/index.d.ts vendored
View File

@ -3913,6 +3913,11 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
name: string, name: string,
options?: ChannelWebhookCreateOptions, options?: ChannelWebhookCreateOptions,
): Promise<Webhook>; ): Promise<Webhook>;
public addFollower(
channel: NewsChannel | Snowflake,
targetChannel: TextChannelResolvable,
reason?: string,
): Promise<Snowflake>;
public edit(channel: GuildChannelResolvable, data: ChannelData, reason?: string): Promise<GuildChannel>; public edit(channel: GuildChannelResolvable, data: ChannelData, reason?: string): Promise<GuildChannel>;
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<GuildBasedChannel | null>; public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<GuildBasedChannel | null>;
public fetch( public fetch(