Skip to content

Commit 555961b

Browse files
refactor(GuildChannelManager): improve addFollower errors (#10277)
refactor(GuildChannelManager): improve errors Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 92c1a51 commit 555961b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/discord.js/src/managers/GuildChannelManager.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,29 @@ class GuildChannelManager extends CachedManager {
9898
return super.resolveId(channel);
9999
}
100100

101+
/**
102+
* Data that can be resolved to a News Channel object. This can be:
103+
* * A NewsChannel object
104+
* * A Snowflake
105+
* @typedef {NewsChannel|Snowflake} NewsChannelResolvable
106+
*/
107+
101108
/**
102109
* Adds the target channel to a channel's followers.
103-
* @param {NewsChannel|Snowflake} channel The channel to follow
110+
* @param {NewsChannelResolvable} channel The channel to follow
104111
* @param {TextChannelResolvable} targetChannel The channel where published announcements will be posted at
105112
* @param {string} [reason] Reason for creating the webhook
106113
* @returns {Promise<Snowflake>} Returns created target webhook id.
107114
*/
108115
async addFollower(channel, targetChannel, reason) {
109116
const channelId = this.resolveId(channel);
117+
if (!channelId) {
118+
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'NewsChannelResolvable');
119+
}
110120
const targetChannelId = this.resolveId(targetChannel);
111-
if (!channelId || !targetChannelId) throw new Error(ErrorCodes.GuildChannelResolve);
121+
if (!targetChannelId) {
122+
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'targetChannel', 'TextChannelResolvable');
123+
}
112124
const { webhook_id } = await this.client.rest.post(Routes.channelFollowers(channelId), {
113125
body: { webhook_channel_id: targetChannelId },
114126
reason,

packages/discord.js/typings/index.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,8 @@ export class NewsChannel extends BaseGuildTextChannel {
24642464
public addFollower(channel: TextChannelResolvable, reason?: string): Promise<NewsChannel>;
24652465
}
24662466

2467+
export type NewsChannelResolvable = NewsChannel | Snowflake;
2468+
24672469
export class OAuth2Guild extends BaseGuild {
24682470
private constructor(client: Client<true>, data: RawOAuth2GuildData);
24692471
public owner: boolean;
@@ -4219,7 +4221,7 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
42194221
public guild: Guild;
42204222

42214223
public addFollower(
4222-
channel: NewsChannel | Snowflake,
4224+
channel: NewsChannelResolvable,
42234225
targetChannel: TextChannelResolvable,
42244226
reason?: string,
42254227
): Promise<Snowflake>;

0 commit comments

Comments
 (0)