diff --git a/src/helpers/guilds/create_guild.ts b/src/helpers/guilds/create_guild.ts index cd9d43a11..e960103bf 100644 --- a/src/helpers/guilds/create_guild.ts +++ b/src/helpers/guilds/create_guild.ts @@ -1,16 +1,25 @@ +import { botId } from "../../bot.ts"; +import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { CreateGuild } from "../../types/guilds/create_guild.ts"; import { DiscordGuild } from "../../types/guilds/guild.ts"; import { endpoints } from "../../util/constants.ts"; +import { getMember } from "../members/get_member.ts"; /** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */ export async function createGuild(options: CreateGuild) { - const guild = (await rest.runMethod( + const result = (await rest.runMethod( "post", endpoints.GUILDS, - options, + options )) as DiscordGuild; - return structures.createDiscordenoGuild(guild, 0); + const guild = await structures.createDiscordenoGuild(result, 0); + // MANUALLY CACHE THE GUILD + await cacheHandlers.set("guilds", guild.id, guild); + // MANUALLY CACHE THE BOT + await getMember(guild.id, botId) + + return guild; } diff --git a/tests/guilds/create_guild.ts b/tests/guilds/create_guild.ts index b78189573..b1af1ee9b 100644 --- a/tests/guilds/create_guild.ts +++ b/tests/guilds/create_guild.ts @@ -13,6 +13,7 @@ Deno.test({ // Assertions assertExists(guild); + assertExists(guild.id); tempData.guildId = guild.id; @@ -20,7 +21,7 @@ Deno.test({ delayUntil(10000, () => cache.guilds.has(guild.id)); if (!cache.guilds.has(guild.id)) { - throw new Error("The guild seemed to be created but it was not cached."); + throw new Error(`The guild seemed to be created but it was not cached. ${JSON.stringify(guild)}`); } }, ...defaultTestOptions, diff --git a/tests/messages/add_reaction.ts b/tests/messages/add_reaction.ts index b39b1b925..ed550d693 100644 --- a/tests/messages/add_reaction.ts +++ b/tests/messages/add_reaction.ts @@ -33,7 +33,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { name: "blamewolf", image: "https://cdn.discordapp.com/emojis/814955268123000832.png", roles: [], - }, + } ) ).id }>`; @@ -47,7 +47,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { delayUntil( 10000, - () => cache.messages.get(message.id)?.reactions?.length > 0, + () => (cache.messages.get(message.id)?.reactions?.length || 0) > 0 ); assertEquals( @@ -55,9 +55,9 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { .get(message.id) ?.reactions?.filter( (reaction: DiscordReaction) => - reaction.emoji?.name === (custom ? "blamewolf" : "❤"), + reaction.emoji?.name === (custom ? "blamewolf" : "❤") ).length, - 1, + 1 ); }