Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(GuildChannelManager): add .addFollower() method #8567

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/discord.js/src/managers/GuildChannelManager.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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