Skip to content

Commit

Permalink
feat(GuildChannelManager): add .addFollower() method (#8567)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
4 people committed Oct 16, 2022
1 parent 4f3c136 commit caeb1cb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/discord.js/src/managers/GuildChannelManager.js
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -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]>;
Expand Down

0 comments on commit caeb1cb

Please sign in to comment.