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

refactor(GuildChannelManager): improve addFollower errors #10277

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/discord.js/src/managers/GuildChannelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,29 @@ class GuildChannelManager extends CachedManager {
return super.resolveId(channel);
}

/**
* Data that can be resolved to a News Channel object. This can be:
* * A NewsChannel object
* * A Snowflake
* @typedef {NewsChannel|Snowflake} NewsChannelResolvable
*/

/**
* Adds the target channel to a channel's followers.
* @param {NewsChannel|Snowflake} channel The channel to follow
* @param {NewsChannelResolvable} 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.
*/
async addFollower(channel, targetChannel, reason) {
const channelId = this.resolveId(channel);
if (!channelId) {
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'NewsChannelResolvable');
}
didinele marked this conversation as resolved.
Show resolved Hide resolved
const targetChannelId = this.resolveId(targetChannel);
if (!channelId || !targetChannelId) throw new Error(ErrorCodes.GuildChannelResolve);
if (!targetChannelId) {
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'targetChannel', 'TextChannelResolvable');
}
const { webhook_id } = await this.client.rest.post(Routes.channelFollowers(channelId), {
body: { webhook_channel_id: targetChannelId },
reason,
Expand Down
4 changes: 3 additions & 1 deletion packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,8 @@ export class NewsChannel extends BaseGuildTextChannel {
public addFollower(channel: TextChannelResolvable, reason?: string): Promise<NewsChannel>;
}

export type NewsChannelResolvable = NewsChannel | Snowflake;

export class OAuth2Guild extends BaseGuild {
private constructor(client: Client<true>, data: RawOAuth2GuildData);
public owner: boolean;
Expand Down Expand Up @@ -4219,7 +4221,7 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
public guild: Guild;

public addFollower(
channel: NewsChannel | Snowflake,
channel: NewsChannelResolvable,
targetChannel: TextChannelResolvable,
reason?: string,
): Promise<Snowflake>;
Expand Down
Loading