diff --git a/packages/discord.js/src/managers/GuildChannelManager.js b/packages/discord.js/src/managers/GuildChannelManager.js index 99405be03c3f..ef4f2a8057a8 100644 --- a/packages/discord.js/src/managers/GuildChannelManager.js +++ b/packages/discord.js/src/managers/GuildChannelManager.js @@ -105,12 +105,19 @@ class GuildChannelManager extends CachedManager { * @typedef {AnnouncementChannel|Snowflake} AnnouncementChannelResolvable */ + /** + * Represents the followed channel data. + * @typedef {Object} FollowedChannelData + * @property {Snowflake} channelId Source channel id + * @property {Snowflake} webhookId Created webhook id in the target channel + */ + /** * Adds the target channel to a channel's followers. * @param {AnnouncementChannelResolvable} 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} Returns created target webhook id. + * @returns {Promise} Returns the data for the followed channel */ async addFollower(channel, targetChannel, reason) { const channelId = this.resolveId(channel); @@ -121,11 +128,11 @@ class GuildChannelManager extends CachedManager { if (!targetChannelId) { throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'targetChannel', 'TextChannelResolvable'); } - const { webhook_id } = await this.client.rest.post(Routes.channelFollowers(channelId), { + const data = await this.client.rest.post(Routes.channelFollowers(channelId), { body: { webhook_channel_id: targetChannelId }, reason, }); - return webhook_id; + return { channelId: data.channel_id, webhookId: data.webhook_id }; } /** diff --git a/packages/discord.js/src/structures/AnnouncementChannel.js b/packages/discord.js/src/structures/AnnouncementChannel.js index a23f8b26b67f..4fb44e300f22 100644 --- a/packages/discord.js/src/structures/AnnouncementChannel.js +++ b/packages/discord.js/src/structures/AnnouncementChannel.js @@ -1,8 +1,6 @@ 'use strict'; -const { Routes } = require('discord-api-types/v10'); const BaseGuildTextChannel = require('./BaseGuildTextChannel'); -const { DiscordjsError, ErrorCodes } = require('../errors'); /** * Represents a guild announcement channel on Discord. @@ -13,7 +11,7 @@ class AnnouncementChannel extends BaseGuildTextChannel { * Adds the target to this channel's followers. * @param {TextChannelResolvable} channel The channel where the webhook should be created * @param {string} [reason] Reason for creating the webhook - * @returns {Promise} + * @returns {Promise} Returns the data for the followed channel * @example * if (channel.type === ChannelType.GuildAnnouncement) { * channel.addFollower('222197033908436994', 'Important announcements') @@ -22,10 +20,7 @@ class AnnouncementChannel extends BaseGuildTextChannel { * } */ async addFollower(channel, reason) { - const channelId = this.guild.channels.resolveId(channel); - if (!channelId) throw new DiscordjsError(ErrorCodes.GuildChannelResolve); - await this.client.rest.post(Routes.channelFollowers(this.id), { body: { webhook_channel_id: channelId }, reason }); - return this; + return this.guild.channels.addFollower(this, channel, reason); } } diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 7da648484524..d838dff8a8b4 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2585,7 +2585,7 @@ export class ModalSubmitInteraction extend export class AnnouncementChannel extends BaseGuildTextChannel { public threads: GuildTextThreadManager; public type: ChannelType.GuildAnnouncement; - public addFollower(channel: TextChannelResolvable, reason?: string): Promise; + public addFollower(channel: TextChannelResolvable, reason?: string): Promise; } export type AnnouncementChannelResolvable = AnnouncementChannel | Snowflake; @@ -4210,6 +4210,11 @@ export class GuildApplicationCommandManager extends ApplicationCommandManager>; } +export interface FollowedChannelData { + channelId: Snowflake; + webhookId: Snowflake; +} + export type MappedGuildChannelTypes = { [ChannelType.GuildCategory]: CategoryChannel; } & MappedChannelCategoryTypes; @@ -4225,7 +4230,7 @@ export class GuildChannelManager extends CachedManager; + ): Promise; public create( options: GuildChannelCreateOptions & { type: Type }, ): Promise;