Files
discordeno/helpers/channels/getChannel.ts
T
Skillz4Killz 3a5bdce32d feat: helpers support strings in args (#2478)
* fix: helpers support strings in args

* fix: fmt
2022-09-15 20:59:02 -05:00

31 lines
1.0 KiB
TypeScript

import type { Bot } from "../../bot.ts";
import { Channel } from "../../transformers/channel.ts";
import { DiscordChannel } from "../../types/discord.ts";
import { BigString } from "../../types/shared.ts";
/**
* Gets a channel by its ID.
*
* @param bot - The bot instance to use to make the request.
* @param channelId - The ID of the channel to get.
* @returns An instance of {@link Channel}.
*
* @remarks
* If the channel is a thread, a {@link ThreadMember} object is included in the result.
*
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel}
*/
export async function getChannel(bot: Bot, channelId: BigString): Promise<Channel> {
const result = await bot.rest.runMethod<DiscordChannel>(
bot.rest,
"GET",
bot.constants.routes.CHANNEL(channelId),
);
// IF A CHANNEL DOESN'T EXIST, DISCORD RETURNS `{}`
return bot.transformers.channel(bot, {
channel: result,
guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined,
});
}