diff --git a/helpers/channels/createChannel.ts b/helpers/channels/createChannel.ts index 1d399ca15..394fb5725 100644 --- a/helpers/channels/createChannel.ts +++ b/helpers/channels/createChannel.ts @@ -24,7 +24,7 @@ import { BigString, ChannelTypes } from "../../types/shared.ts"; * * @see {@link https://discord.com/developers/docs/resources/guild#create-guild-channel} */ -export async function createChannel(bot: Bot, guildId: BigString, options?: CreateGuildChannel): Promise { +export async function createChannel(bot: Bot, guildId: BigString, options: CreateGuildChannel): Promise { // BITRATE IS IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000 if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000; diff --git a/helpers/stickers/createGuildSticker.ts b/helpers/stickers/createGuildSticker.ts index 2e2322bcd..d4b883878 100644 --- a/helpers/stickers/createGuildSticker.ts +++ b/helpers/stickers/createGuildSticker.ts @@ -22,6 +22,10 @@ export async function createGuildSticker( guildId: bigint, options: CreateGuildStickerOptions, ): Promise { + if (options.file && !options.file.startsWith("data:image/")) { + options.file = await bot.utils.urlToBase64(options.file); + } + const result = await bot.rest.runMethod(bot.rest, "POST", bot.constants.routes.GUILD_STICKERS(guildId), { name: options.name, description: options.description, @@ -40,5 +44,5 @@ export interface CreateGuildStickerOptions extends WithReason { /** Autocomplete/suggestion tags for the sticker (max 200 characters) */ tags: string; /** The sticker file to upload, must be a PNG, APNG, or Lottie JSON file, max 500 KB */ - file: FileContent; + file: string; } diff --git a/rest/runMethod.ts b/rest/runMethod.ts index 974082395..ad34db4a2 100644 --- a/rest/runMethod.ts +++ b/rest/runMethod.ts @@ -41,7 +41,7 @@ export async function runMethod( if (!result.ok) { const err = await result.json().catch(() => {}); // Legacy Handling to not break old code or when body is missing - if (!err.body) throw new Error(`Error: ${err.message ?? result.statusText}`); + if (!err?.body) throw new Error(`Error: ${err.message ?? result.statusText}`); throw rest.convertRestError(errorStack, err); } diff --git a/tests/misc/rateLimit.test.ts b/tests/misc/rateLimit.test.ts index 2c0cc0dda..1e40eea5f 100644 --- a/tests/misc/rateLimit.test.ts +++ b/tests/misc/rateLimit.test.ts @@ -3,7 +3,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test("[Misc] Rate Limit Test", async () => { const bot = loadBot(); - const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID); + const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "test" }); await Promise.all(Array(10).map(() => bot.helpers.sendMessage(channel.id, { content: "Rate Limit Test" }))); await bot.helpers.deleteChannel(channel.id); }); diff --git a/tests/mod.ts b/tests/mod.ts index 12827381a..548fc8a27 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -1,4 +1,4 @@ -import { createBot, createRestManager, runMethod } from "../mod.ts"; +import { createBot, createRestManager } from "../mod.ts"; import { dotenv } from "./deps.ts"; dotenv({ export: true, path: `${Deno.cwd()}/.env` }); diff --git a/tests/stickers/createGuildSticker.test.ts b/tests/stickers/createGuildSticker.test.ts index 60b92e6f4..473efbdf8 100644 --- a/tests/stickers/createGuildSticker.test.ts +++ b/tests/stickers/createGuildSticker.test.ts @@ -9,14 +9,14 @@ Deno.test("[stickers] Create guild sticker", async () => { name: "sticker name", description: "sticker description", tags: "sticker tags", - file: { blob: new Blob(), name: "test.png" }, + file: "https://cdn.discordapp.com/emojis/785403373817823272.png", }); assertEquals(sticker.name, "sticker name"); assertEquals(sticker.description, "sticker description"); assertEquals(sticker.tags, "sticker tags"); - const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID); + const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "test" }); const message = await bot.helpers.sendMessage(channel.id, { stickerIds: [sticker.id] }); assertEquals(message.stickerItems?.[0].formatType, StickerFormatTypes.Png); @@ -24,4 +24,5 @@ Deno.test("[stickers] Create guild sticker", async () => { assertEquals(message.stickerItems?.[0].name, sticker.name); await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id); + await bot.helpers.deleteChannel(channel.id); }); diff --git a/tests/stickers/deleteGuildSticker.test.ts b/tests/stickers/deleteGuildSticker.test.ts index de0cac831..c07604a10 100644 --- a/tests/stickers/deleteGuildSticker.test.ts +++ b/tests/stickers/deleteGuildSticker.test.ts @@ -8,7 +8,7 @@ Deno.test("[stickers] Delete guild sticker", async () => { name: "sticker name", description: "sticker description", tags: "sticker tags", - file: { blob: new Blob(), name: "sticker file name" }, + file: "https://cdn.discordapp.com/emojis/785403373817823272.png", }); await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id); await assertRejects(() => bot.helpers.getGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id)); diff --git a/tests/stickers/editGuildSticker.test.ts b/tests/stickers/editGuildSticker.test.ts index 7556e6891..de7304508 100644 --- a/tests/stickers/editGuildSticker.test.ts +++ b/tests/stickers/editGuildSticker.test.ts @@ -8,7 +8,7 @@ Deno.test("[stickers] Edit guild sticker", async () => { name: "test", description: "test", tags: "test", - file: { blob: new Blob(), name: "test.png" }, + file: "https://cdn.discordapp.com/emojis/785403373817823272.png", }); const editSticker = await bot.helpers.editGuildSticker(CACHED_COMMUNITY_GUILD_ID, createSticker.id, { name: "sticker name", diff --git a/tests/stickers/getGuildSticker.test.ts b/tests/stickers/getGuildSticker.test.ts index 236606567..0a8900dac 100644 --- a/tests/stickers/getGuildSticker.test.ts +++ b/tests/stickers/getGuildSticker.test.ts @@ -8,7 +8,7 @@ Deno.test("[stickers] Get guild sticker", async () => { name: "sticker name", description: "sticker description", tags: "sticker tags", - file: { blob: new Blob(), name: "sticker file name" }, + file: "https://cdn.discordapp.com/emojis/785403373817823272.png", }); const getSticker = await bot.helpers.getGuildSticker(CACHED_COMMUNITY_GUILD_ID, createSticker.id); assertEquals(getSticker.name, "sticker name"); diff --git a/tests/stickers/getGuildStickers.test.ts b/tests/stickers/getGuildStickers.test.ts index ea8c936c5..747b1561d 100644 --- a/tests/stickers/getGuildStickers.test.ts +++ b/tests/stickers/getGuildStickers.test.ts @@ -8,13 +8,13 @@ Deno.test("[stickers] Get guild stickers", async () => { name: "sticker 1", description: "sticker 1", tags: "sticker tags 1", - file: { blob: new Blob(), name: "test1.png" }, + file: "https://cdn.discordapp.com/emojis/785403373817823272.png", }); const sticker2 = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, { name: "sticker 2", description: "sticker 2", tags: "sticker tags 2", - file: { blob: new Blob(), name: "test2.png" }, + file: "https://cdn.discordapp.com/emojis/785403373817823272.png", }); const stickers = await bot.helpers.getGuildStickers(CACHED_COMMUNITY_GUILD_ID); assertEquals(stickers.size > 1, true); diff --git a/types/discord.ts b/types/discord.ts index 938a8c835..67d5a040d 100644 --- a/types/discord.ts +++ b/types/discord.ts @@ -1260,8 +1260,6 @@ export interface DiscordInputTextComponent { min_length?: number; /** The maximum length of the text the user has to provide */ max_length?: number; - /** Whether or not this input is required. */ - required?: boolean; /** Pre-filled value for input text. */ value?: string; } @@ -2103,6 +2101,8 @@ export interface DiscordComponent { max_length?: number; /** a list of child components */ components?: DiscordComponent[]; + /** whether this component is required to be filled, default true */ + required?: boolean; } /** https://discord.com/developers/docs/topics/gateway#channel-pins-update */