Skip to content

Commit

Permalink
feat(GuildChannelManager): add addFollower (#9050)
Browse files Browse the repository at this point in the history
* feat: addFolower method

* Update src/structures/NewsChannel.js

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
  • Loading branch information
jaw0r3k and Jiralite committed Feb 17, 2023
1 parent 69d71e9 commit 86329ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/managers/GuildChannelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,24 @@ class GuildChannelManager extends CachedManager {
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.
* @typedef {Object} ChannelData
Expand Down
1 change: 1 addition & 0 deletions src/structures/NewsChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { Error } = require('../errors');
class NewsChannel extends BaseGuildTextChannel {
/**
* 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 {string} [reason] Reason for creating the webhook
* @returns {Promise<NewsChannel>}
Expand Down
5 changes: 5 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,11 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
name: string,
options?: TextChannel | NewsChannel | VoiceChannel | Snowflake,
): Promise<Webhook>;
public addFollower(
channel: NewsChannel | Snowflake,
targetChannel: TextChannelResolvable,
reason?: string,
): Promise<Snowflake>;
public edit(channel: GuildChannelResolvable, data: ChannelData, reason?: string): Promise<GuildChannel>;
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<GuildBasedChannel | null>;
public fetch(
Expand Down

0 comments on commit 86329ad

Please sign in to comment.