feat(NewsChannel)!: return followed channel data (#8566)

BREAKING CHANGE: `GuildChannelManager#addFollower` and `AnnouncementChannel#addFollower` now return `FollowedChannelData`
This commit is contained in:
Synbulat Biishev
2025-01-04 20:43:22 +03:00
committed by GitHub
parent 1986c2d2a8
commit f5d2926c5a
3 changed files with 19 additions and 12 deletions

View File

@@ -105,12 +105,19 @@ class GuildChannelManager extends CachedManager {
* @typedef {AnnouncementChannel|Snowflake} AnnouncementChannelResolvable * @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. * Adds the target channel to a channel's followers.
* @param {AnnouncementChannelResolvable} channel The channel to follow * @param {AnnouncementChannelResolvable} channel The channel to follow
* @param {TextChannelResolvable} targetChannel The channel where published announcements will be posted at * @param {TextChannelResolvable} targetChannel The channel where published announcements will be posted at
* @param {string} [reason] Reason for creating the webhook * @param {string} [reason] Reason for creating the webhook
* @returns {Promise<Snowflake>} Returns created target webhook id. * @returns {Promise<FollowedChannelData>} Returns the data for the followed channel
*/ */
async addFollower(channel, targetChannel, reason) { async addFollower(channel, targetChannel, reason) {
const channelId = this.resolveId(channel); const channelId = this.resolveId(channel);
@@ -121,11 +128,11 @@ class GuildChannelManager extends CachedManager {
if (!targetChannelId) { if (!targetChannelId) {
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'targetChannel', 'TextChannelResolvable'); 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 }, body: { webhook_channel_id: targetChannelId },
reason, reason,
}); });
return webhook_id; return { channelId: data.channel_id, webhookId: data.webhook_id };
} }
/** /**

View File

@@ -1,8 +1,6 @@
'use strict'; 'use strict';
const { Routes } = require('discord-api-types/v10');
const BaseGuildTextChannel = require('./BaseGuildTextChannel'); const BaseGuildTextChannel = require('./BaseGuildTextChannel');
const { DiscordjsError, ErrorCodes } = require('../errors');
/** /**
* Represents a guild announcement channel on Discord. * Represents a guild announcement channel on Discord.
@@ -13,7 +11,7 @@ class AnnouncementChannel extends BaseGuildTextChannel {
* Adds the target to this channel's followers. * Adds the target to this channel's followers.
* @param {TextChannelResolvable} channel The channel where the webhook should be created * @param {TextChannelResolvable} channel The channel where the webhook should be created
* @param {string} [reason] Reason for creating the webhook * @param {string} [reason] Reason for creating the webhook
* @returns {Promise<AnnouncementChannel>} * @returns {Promise<FollowedChannelData>} Returns the data for the followed channel
* @example * @example
* if (channel.type === ChannelType.GuildAnnouncement) { * if (channel.type === ChannelType.GuildAnnouncement) {
* channel.addFollower('222197033908436994', 'Important announcements') * channel.addFollower('222197033908436994', 'Important announcements')
@@ -22,10 +20,7 @@ class AnnouncementChannel extends BaseGuildTextChannel {
* } * }
*/ */
async addFollower(channel, reason) { async addFollower(channel, reason) {
const channelId = this.guild.channels.resolveId(channel); return this.guild.channels.addFollower(this, channel, reason);
if (!channelId) throw new DiscordjsError(ErrorCodes.GuildChannelResolve);
await this.client.rest.post(Routes.channelFollowers(this.id), { body: { webhook_channel_id: channelId }, reason });
return this;
} }
} }

View File

@@ -2585,7 +2585,7 @@ export class ModalSubmitInteraction<Cached extends CacheType = CacheType> extend
export class AnnouncementChannel extends BaseGuildTextChannel { export class AnnouncementChannel extends BaseGuildTextChannel {
public threads: GuildTextThreadManager<AllowedThreadTypeForAnnouncementChannel>; public threads: GuildTextThreadManager<AllowedThreadTypeForAnnouncementChannel>;
public type: ChannelType.GuildAnnouncement; public type: ChannelType.GuildAnnouncement;
public addFollower(channel: TextChannelResolvable, reason?: string): Promise<AnnouncementChannel>; public addFollower(channel: TextChannelResolvable, reason?: string): Promise<FollowedChannelData>;
} }
export type AnnouncementChannelResolvable = AnnouncementChannel | Snowflake; export type AnnouncementChannelResolvable = AnnouncementChannel | Snowflake;
@@ -4210,6 +4210,11 @@ export class GuildApplicationCommandManager extends ApplicationCommandManager<Ap
public set(commands: readonly ApplicationCommandDataResolvable[]): Promise<Collection<Snowflake, ApplicationCommand>>; public set(commands: readonly ApplicationCommandDataResolvable[]): Promise<Collection<Snowflake, ApplicationCommand>>;
} }
export interface FollowedChannelData {
channelId: Snowflake;
webhookId: Snowflake;
}
export type MappedGuildChannelTypes = { export type MappedGuildChannelTypes = {
[ChannelType.GuildCategory]: CategoryChannel; [ChannelType.GuildCategory]: CategoryChannel;
} & MappedChannelCategoryTypes; } & MappedChannelCategoryTypes;
@@ -4225,7 +4230,7 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
channel: AnnouncementChannelResolvable, channel: AnnouncementChannelResolvable,
targetChannel: TextChannelResolvable, targetChannel: TextChannelResolvable,
reason?: string, reason?: string,
): Promise<Snowflake>; ): Promise<FollowedChannelData>;
public create<Type extends GuildChannelTypes>( public create<Type extends GuildChannelTypes>(
options: GuildChannelCreateOptions & { type: Type }, options: GuildChannelCreateOptions & { type: Type },
): Promise<MappedGuildChannelTypes[Type]>; ): Promise<MappedGuildChannelTypes[Type]>;