Files
discordeno/helpers/guilds/getGuild.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

29 lines
745 B
TypeScript

import type { Bot } from "../../bot.ts";
import { DiscordGuild } from "../../types/discord.ts";
/**
* This function fetches a guild's data. This is not the same data as a GUILD_CREATE.
* So it does not cache the guild, you must do it manually.
*/
export async function getGuild(
bot: Bot,
guildId: bigint,
options: { counts?: boolean } = {
counts: true,
},
) {
const result = await bot.rest.runMethod<DiscordGuild>(
bot.rest,
"GET",
bot.constants.routes.GUILD(guildId, options.counts),
);
// Sometimes the guild is not found, so we need to check for it.
if (!result.id) return;
return bot.transformers.guild(bot, {
guild: result,
shardId: bot.utils.calculateShardId(bot.gateway, guildId),
});
}