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
*/
/**
* 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<Snowflake>} Returns created target webhook id.
* @returns {Promise<FollowedChannelData>} 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 };
}
/**

View File

@@ -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<AnnouncementChannel>}
* @returns {Promise<FollowedChannelData>} 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);
}
}

View File

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