Skip to content

Commit caeb1cb

Browse files
SyjaloJiralitekyranetkodiakhq[bot]
authored
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>
1 parent 4f3c136 commit caeb1cb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/discord.js/src/managers/GuildChannelManager.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ class GuildChannelManager extends CachedManager {
9898
return super.resolveId(channel);
9999
}
100100

101+
/**
102+
* Adds the target channel to a channel's followers.
103+
* @param {NewsChannel|Snowflake} channel The channel to follow
104+
* @param {TextChannelResolvable} targetChannel The channel where published announcements will be posted at
105+
* @param {string} [reason] Reason for creating the webhook
106+
* @returns {Promise<Snowflake>} Returns created target webhook id.
107+
*/
108+
async addFollower(channel, targetChannel, reason) {
109+
const channelId = this.resolveId(channel);
110+
const targetChannelId = this.resolveId(targetChannel);
111+
if (!channelId || !targetChannelId) throw new Error(ErrorCodes.GuildChannelResolve);
112+
const { webhook_id } = await this.client.rest.post(Routes.channelFollowers(channelId), {
113+
body: { webhook_channel_id: targetChannelId },
114+
reason,
115+
});
116+
return webhook_id;
117+
}
118+
101119
/**
102120
* Options used to create a new channel in a guild.
103121
* @typedef {CategoryCreateChannelOptions} GuildChannelCreateOptions

packages/discord.js/typings/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3457,6 +3457,11 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
34573457
public get channelCountWithoutThreads(): number;
34583458
public guild: Guild;
34593459

3460+
public addFollower(
3461+
channel: NewsChannel | Snowflake,
3462+
targetChannel: TextChannelResolvable,
3463+
reason?: string,
3464+
): Promise<Snowflake>;
34603465
public create<T extends GuildChannelTypes>(
34613466
options: GuildChannelCreateOptions & { type: T },
34623467
): Promise<MappedGuildChannelTypes[T]>;

0 commit comments

Comments
 (0)