mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(GuildChannelManager): add .addFollower() method (#8567)
* 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 <kyradiscord@gmail.com> * docs: update description Co-authored-by: A. Román <kyradiscord@gmail.com> Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: A. Román <kyradiscord@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -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<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(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
|
||||
|
||||
5
packages/discord.js/typings/index.d.ts
vendored
5
packages/discord.js/typings/index.d.ts
vendored
@@ -3457,6 +3457,11 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
|
||||
public get channelCountWithoutThreads(): number;
|
||||
public guild: Guild;
|
||||
|
||||
public addFollower(
|
||||
channel: NewsChannel | Snowflake,
|
||||
targetChannel: TextChannelResolvable,
|
||||
reason?: string,
|
||||
): Promise<Snowflake>;
|
||||
public create<T extends GuildChannelTypes>(
|
||||
options: GuildChannelCreateOptions & { type: T },
|
||||
): Promise<MappedGuildChannelTypes[T]>;
|
||||
|
||||
Reference in New Issue
Block a user