mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { cacheHandlers } from "../../cache.ts";
|
|
import { rest } from "../../rest/rest.ts";
|
|
import { structures } from "../../structures/mod.ts";
|
|
import { Guild } from "../../types/guilds/guild.ts";
|
|
import { endpoints } from "../../util/constants.ts";
|
|
import { ws } from "../../ws/ws.ts";
|
|
|
|
/**
|
|
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()
|
|
*
|
|
* Advanced Devs:
|
|
* 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(
|
|
guildId: string,
|
|
options: { counts?: boolean; addToCache?: boolean } = {
|
|
counts: true,
|
|
addToCache: true,
|
|
},
|
|
) {
|
|
const result = await rest.runMethod<Guild>(
|
|
"get",
|
|
endpoints.GUILDS_BASE(guildId),
|
|
{
|
|
with_counts: options.counts,
|
|
},
|
|
);
|
|
|
|
const structure = await structures.createDiscordenoGuild(
|
|
result,
|
|
(BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards),
|
|
);
|
|
|
|
if (options.addToCache) {
|
|
await cacheHandlers.set("guilds", guildId, structure);
|
|
}
|
|
|
|
return structure;
|
|
}
|