mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
refactor(GuildChannelManager): improve addFollower errors (#10277)
refactor(GuildChannelManager): improve errors Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -98,17 +98,29 @@ class GuildChannelManager extends CachedManager {
|
|||||||
return super.resolveId(channel);
|
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.
|
* 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 {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<Snowflake>} Returns created target webhook id.
|
||||||
*/
|
*/
|
||||||
async addFollower(channel, targetChannel, reason) {
|
async addFollower(channel, targetChannel, reason) {
|
||||||
const channelId = this.resolveId(channel);
|
const channelId = this.resolveId(channel);
|
||||||
|
if (!channelId) {
|
||||||
|
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'NewsChannelResolvable');
|
||||||
|
}
|
||||||
const targetChannelId = this.resolveId(targetChannel);
|
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), {
|
const { webhook_id } = await this.client.rest.post(Routes.channelFollowers(channelId), {
|
||||||
body: { webhook_channel_id: targetChannelId },
|
body: { webhook_channel_id: targetChannelId },
|
||||||
reason,
|
reason,
|
||||||
|
|||||||
4
packages/discord.js/typings/index.d.ts
vendored
4
packages/discord.js/typings/index.d.ts
vendored
@@ -2464,6 +2464,8 @@ export class NewsChannel extends BaseGuildTextChannel {
|
|||||||
public addFollower(channel: TextChannelResolvable, reason?: string): Promise<NewsChannel>;
|
public addFollower(channel: TextChannelResolvable, reason?: string): Promise<NewsChannel>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type NewsChannelResolvable = NewsChannel | Snowflake;
|
||||||
|
|
||||||
export class OAuth2Guild extends BaseGuild {
|
export class OAuth2Guild extends BaseGuild {
|
||||||
private constructor(client: Client<true>, data: RawOAuth2GuildData);
|
private constructor(client: Client<true>, data: RawOAuth2GuildData);
|
||||||
public owner: boolean;
|
public owner: boolean;
|
||||||
@@ -4219,7 +4221,7 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
|
|||||||
public guild: Guild;
|
public guild: Guild;
|
||||||
|
|
||||||
public addFollower(
|
public addFollower(
|
||||||
channel: NewsChannel | Snowflake,
|
channel: NewsChannelResolvable,
|
||||||
targetChannel: TextChannelResolvable,
|
targetChannel: TextChannelResolvable,
|
||||||
reason?: string,
|
reason?: string,
|
||||||
): Promise<Snowflake>;
|
): Promise<Snowflake>;
|
||||||
|
|||||||
Reference in New Issue
Block a user