Files
discordeno/helpers/channels/getChannel.ts
ITOH 03996c5f58 refactor: revert "feat: base plugin lib idea (#2308)" (#2336)
* Revert "feat: base plugin lib idea (#2308)"

This reverts commit ffe7cdbc6f.

* fmt
2022-07-02 14:24:43 +01:00

20 lines
601 B
TypeScript

import type { Bot } from "../../bot.ts";
import { DiscordChannel } from "../../types/discord.ts";
/** Fetches a single channel object from the api. */
export async function getChannel(bot: Bot, channelId: bigint) {
const result = await bot.rest.runMethod<DiscordChannel>(
bot.rest,
"GET",
bot.constants.routes.CHANNEL(channelId),
);
// IF A CHANNEL DOESN'T EXIST, DISCORD RETURNS `{}`
return result.id
? bot.transformers.channel(bot, {
channel: result,
guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined,
})
: undefined;
}