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(NewsChannel)!: return followed channel data #8566

13 changes: 10 additions & 3 deletions packages/discord.js/src/managers/GuildChannelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,19 @@ class GuildChannelManager extends CachedManager {
* @typedef {AnnouncementChannel|Snowflake} AnnouncementChannelResolvable
*/

/**
* Represents the followed channel data.
* @typedef {Object} FollowedChannel
* @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<FollowedChannel>} Returns a followed channel object.
*/
async addFollower(channel, targetChannel, reason) {
const channelId = this.resolveId(channel);
Expand All @@ -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 };
}

/**
Expand Down
9 changes: 2 additions & 7 deletions packages/discord.js/src/structures/AnnouncementChannel.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<FollowedChannel>} Returns a followed channel object.
* @example
* if (channel.type === ChannelType.GuildAnnouncement) {
* channel.addFollower('222197033908436994', 'Important announcements')
Expand All @@ -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);
}
}

Expand Down
9 changes: 7 additions & 2 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FollowedChannel>;
}

export type AnnouncementChannelResolvable = AnnouncementChannel | Snowflake;
Expand Down Expand Up @@ -4211,6 +4211,11 @@ export class GuildApplicationCommandManager extends ApplicationCommandManager<Ap
public set(commands: readonly ApplicationCommandDataResolvable[]): Promise<Collection<Snowflake, ApplicationCommand>>;
}

export interface FollowedChannel {
channelId: Snowflake;
webhookId: Snowflake;
}
almeidx marked this conversation as resolved.
Show resolved Hide resolved

export type MappedGuildChannelTypes = {
[ChannelType.GuildCategory]: CategoryChannel;
} & MappedChannelCategoryTypes;
Expand All @@ -4226,7 +4231,7 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
channel: AnnouncementChannelResolvable,
targetChannel: TextChannelResolvable,
reason?: string,
): Promise<Snowflake>;
): Promise<FollowedChannel>;
public create<Type extends GuildChannelTypes>(
options: GuildChannelCreateOptions & { type: Type },
): Promise<MappedGuildChannelTypes[Type]>;
Expand Down
Loading