bazlow
bazlow
SIASapphire - Imagine a framework
Created by bazlow on 8/28/2023 in #sapphire-support
@sapphire/discord.js-utilities - isPrivateThreadChannel
Could I query about the return type from the isPrivateThreadChannel. Shouldn't that type-guard instead of being ThreadChannel be PrivateThreadChannel
import { container } from '@sapphire/framework'
import type { PrivateThreadChannel, Snowflake } from 'discord.js'
import { ChannelType } from 'discord.js'

/**
* Attempts to fetch a {@link PrivateThreadChannel} from the provided channelId
*/
export async function getPrivateThreadChannel(channelId: Snowflake): Promise<PrivateThreadChannel> {
const channel = await container.client.channels.fetch(channelId)
if (channel?.type === ChannelType.PrivateThread) {
return channel
}
throw new Error('channelId is not a Private Thread Channel')
}
import { container } from '@sapphire/framework'
import type { PrivateThreadChannel, Snowflake } from 'discord.js'
import { ChannelType } from 'discord.js'

/**
* Attempts to fetch a {@link PrivateThreadChannel} from the provided channelId
*/
export async function getPrivateThreadChannel(channelId: Snowflake): Promise<PrivateThreadChannel> {
const channel = await container.client.channels.fetch(channelId)
if (channel?.type === ChannelType.PrivateThread) {
return channel
}
throw new Error('channelId is not a Private Thread Channel')
}
The function above types the channel differently compared to isPrivateThreadChannel, is this intentional?
8 replies