diff --git a/bot.ts b/bot.ts index e8ba1ac3d..18b9f90c3 100644 --- a/bot.ts +++ b/bot.ts @@ -26,7 +26,7 @@ import { CONTEXT_MENU_COMMANDS_NAME_REGEX, DISCORD_SNOWFLAKE_REGEX, DISCORDENO_VERSION, - endpoints, + routes, SLASH_COMMANDS_NAME_REGEX, USER_AGENT, } from "./util/constants.ts"; @@ -710,7 +710,7 @@ export function createBotConstants() { USER_AGENT, BASE_URL: baseEndpoints.BASE_URL, CDN_URL: baseEndpoints.CDN_URL, - endpoints, + routes, regexes: { SLASH_COMMANDS_NAME_REGEX, CONTEXT_MENU_COMMANDS_NAME_REGEX, diff --git a/helpers/channels/createChannel.ts b/helpers/channels/createChannel.ts index 8f037aceb..523f65204 100644 --- a/helpers/channels/createChannel.ts +++ b/helpers/channels/createChannel.ts @@ -11,7 +11,7 @@ export async function createChannel(bot: Bot, guildId: bigint, options?: CreateG const result = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.GUILD_CHANNELS(guildId), + bot.constants.routes.GUILD_CHANNELS(guildId), options ? { name: options.name, diff --git a/helpers/channels/createStageInstance.ts b/helpers/channels/createStageInstance.ts index b18afdaeb..c4deb1768 100644 --- a/helpers/channels/createStageInstance.ts +++ b/helpers/channels/createStageInstance.ts @@ -6,7 +6,7 @@ export async function createStageInstance(bot: Bot, options: CreateStageInstance const result = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.STAGE_INSTANCES(), + bot.constants.routes.STAGE_INSTANCES(), { channel_id: options.channelId.toString(), topic: options.topic, diff --git a/helpers/channels/deleteChannel.ts b/helpers/channels/deleteChannel.ts index 3d66439b5..c2e7e16b5 100644 --- a/helpers/channels/deleteChannel.ts +++ b/helpers/channels/deleteChannel.ts @@ -6,7 +6,7 @@ export async function deleteChannel(bot: Bot, channelId: bigint, reason?: string await bot.rest.runMethod( bot.rest, "delete", - bot.constants.endpoints.CHANNEL_BASE(channelId), + bot.constants.routes.CHANNEL(channelId), { reason, }, diff --git a/helpers/channels/deleteChannelOverwrite.ts b/helpers/channels/deleteChannelOverwrite.ts index 655ef75c9..0c8e85425 100644 --- a/helpers/channels/deleteChannelOverwrite.ts +++ b/helpers/channels/deleteChannelOverwrite.ts @@ -5,6 +5,6 @@ export async function deleteChannelOverwrite(bot: Bot, channelId: bigint, overwr await bot.rest.runMethod( bot.rest, "delete", - bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId), + bot.constants.routes.CHANNEL_OVERWRITE(channelId, overwriteId), ); } diff --git a/helpers/channels/deleteStageInstance.ts b/helpers/channels/deleteStageInstance.ts index e4f205522..8e9faad64 100644 --- a/helpers/channels/deleteStageInstance.ts +++ b/helpers/channels/deleteStageInstance.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts"; /** Deletes the Stage instance. Requires the user to be a moderator of the Stage channel. */ export async function deleteStageInstance(bot: Bot, channelId: bigint) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.STAGE_INSTANCE(channelId)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.STAGE_INSTANCE(channelId)); } diff --git a/helpers/channels/editChannel.ts b/helpers/channels/editChannel.ts index b15defca4..b611450e5 100644 --- a/helpers/channels/editChannel.ts +++ b/helpers/channels/editChannel.ts @@ -35,7 +35,7 @@ export async function editChannel(bot: Bot, channelId: bigint, options: ModifyCh const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.CHANNEL_BASE(channelId), + bot.constants.routes.CHANNEL(channelId), { name: options.name, topic: options.topic, diff --git a/helpers/channels/editChannelOverwrite.ts b/helpers/channels/editChannelOverwrite.ts index b2df23422..53f44167f 100644 --- a/helpers/channels/editChannelOverwrite.ts +++ b/helpers/channels/editChannelOverwrite.ts @@ -10,7 +10,7 @@ export async function editChannelOverwrite( await bot.rest.runMethod( bot.rest, "put", - bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwrite.id), + bot.constants.routes.CHANNEL_OVERWRITE(channelId, overwrite.id), { allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : "0", deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : "0", diff --git a/helpers/channels/followChannel.ts b/helpers/channels/followChannel.ts index f03134e28..00973e135 100644 --- a/helpers/channels/followChannel.ts +++ b/helpers/channels/followChannel.ts @@ -6,7 +6,7 @@ export async function followChannel(bot: Bot, sourceChannelId: bigint, targetCha const data = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.CHANNEL_FOLLOW(sourceChannelId), + bot.constants.routes.CHANNEL_FOLLOW(sourceChannelId), { webhook_channel_id: targetChannelId, }, diff --git a/helpers/channels/forums/createForumPost.ts b/helpers/channels/forums/createForumPost.ts index 9a5e80d62..a2bd9fe8d 100644 --- a/helpers/channels/forums/createForumPost.ts +++ b/helpers/channels/forums/createForumPost.ts @@ -12,7 +12,7 @@ export async function createForumPost( const result = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.FORUM_START(channelId), + bot.constants.routes.FORUM_START(channelId), { name: options.name, auto_archive_duration: options.autoArchiveDuration, diff --git a/helpers/channels/getChannel.ts b/helpers/channels/getChannel.ts index 60f9d7fe2..76d50c821 100644 --- a/helpers/channels/getChannel.ts +++ b/helpers/channels/getChannel.ts @@ -6,7 +6,7 @@ export async function getChannel(bot: Bot, channelId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.CHANNEL_BASE(channelId), + bot.constants.routes.CHANNEL(channelId), ); // IF A CHANNEL DOESN'T EXIST, DISCORD RETURNS `{}` diff --git a/helpers/channels/getChannelWebhooks.ts b/helpers/channels/getChannelWebhooks.ts index ab212136c..5997f4e3b 100644 --- a/helpers/channels/getChannelWebhooks.ts +++ b/helpers/channels/getChannelWebhooks.ts @@ -7,7 +7,7 @@ export async function getChannelWebhooks(bot: Bot, channelId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId), + bot.constants.routes.CHANNEL_WEBHOOKS(channelId), ); return new Collection(result.map((hook) => { diff --git a/helpers/channels/getChannels.ts b/helpers/channels/getChannels.ts index f79c0a9cb..e1d0ee226 100644 --- a/helpers/channels/getChannels.ts +++ b/helpers/channels/getChannels.ts @@ -7,7 +7,7 @@ export async function getChannels(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_CHANNELS(guildId), + bot.constants.routes.GUILD_CHANNELS(guildId), ); return new Collection( diff --git a/helpers/channels/getPins.ts b/helpers/channels/getPins.ts index 2ea5c1c06..d42e3fbee 100644 --- a/helpers/channels/getPins.ts +++ b/helpers/channels/getPins.ts @@ -6,7 +6,7 @@ export async function getPins(bot: Bot, channelId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.CHANNEL_PINS(channelId), + bot.constants.routes.CHANNEL_PINS(channelId), ); return result.map((msg) => bot.transformers.message(bot, msg)); diff --git a/helpers/channels/getStageInstance.ts b/helpers/channels/getStageInstance.ts index 21fdef5d0..ef98d1f93 100644 --- a/helpers/channels/getStageInstance.ts +++ b/helpers/channels/getStageInstance.ts @@ -6,7 +6,7 @@ export async function getStageInstance(bot: Bot, channelId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.STAGE_INSTANCE(channelId), + bot.constants.routes.STAGE_INSTANCE(channelId), ); return bot.transformers.stageInstance(bot, result); diff --git a/helpers/channels/startTyping.ts b/helpers/channels/startTyping.ts index e73afad38..5357e6099 100644 --- a/helpers/channels/startTyping.ts +++ b/helpers/channels/startTyping.ts @@ -6,5 +6,5 @@ import type { Bot } from "../../bot.ts"; * this endpoint may be called to let the user know that the bot is processing their message. */ export async function startTyping(bot: Bot, channelId: bigint) { - await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.CHANNEL_TYPING(channelId)); + await bot.rest.runMethod(bot.rest, "post", bot.constants.routes.CHANNEL_TYPING(channelId)); } diff --git a/helpers/channels/swapChannels.ts b/helpers/channels/swapChannels.ts index 0f7b9b3be..c6819fb98 100644 --- a/helpers/channels/swapChannels.ts +++ b/helpers/channels/swapChannels.ts @@ -9,7 +9,7 @@ export async function swapChannels(bot: Bot, guildId: bigint, channelPositions: await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.GUILD_CHANNELS(guildId), + bot.constants.routes.GUILD_CHANNELS(guildId), channelPositions.map((channelPosition) => { return { id: channelPosition.id, diff --git a/helpers/channels/threads/addToThread.ts b/helpers/channels/threads/addToThread.ts index a146e48bc..e5c3ca7bb 100644 --- a/helpers/channels/threads/addToThread.ts +++ b/helpers/channels/threads/addToThread.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../../bot.ts"; /** Adds a user to a thread. Requires the ability to send messages in the thread. Requires the thread is not archived. */ export async function addToThread(bot: Bot, threadId: bigint, userId: bigint) { - await bot.rest.runMethod(bot.rest, "put", bot.constants.endpoints.THREAD_USER(threadId, userId)); + await bot.rest.runMethod(bot.rest, "put", bot.constants.routes.THREAD_USER(threadId, userId)); } diff --git a/helpers/channels/threads/getActiveThreads.ts b/helpers/channels/threads/getActiveThreads.ts index 0b660d6b1..5dfb9aa28 100644 --- a/helpers/channels/threads/getActiveThreads.ts +++ b/helpers/channels/threads/getActiveThreads.ts @@ -7,7 +7,7 @@ export async function getActiveThreads(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.THREAD_ACTIVE(guildId), + bot.constants.routes.THREAD_ACTIVE(guildId), ); return { diff --git a/helpers/channels/threads/getArchivedThreads.ts b/helpers/channels/threads/getArchivedThreads.ts index 4d23295ec..84176a835 100644 --- a/helpers/channels/threads/getArchivedThreads.ts +++ b/helpers/channels/threads/getArchivedThreads.ts @@ -11,21 +11,17 @@ export async function getArchivedThreads( }, ) { let url = options?.type === "privateJoinedThreads" - ? bot.constants.endpoints.THREAD_ARCHIVED_PRIVATE_JOINED(channelId) + ? bot.constants.routes.THREAD_ARCHIVED_PRIVATE_JOINED(channelId, options) : options?.type === "private" - ? bot.constants.endpoints.THREAD_ARCHIVED_PRIVATE(channelId) - : bot.constants.endpoints.THREAD_ARCHIVED_PUBLIC(channelId); - if (options) { - url += "?"; + ? bot.constants.routes.THREAD_ARCHIVED_PRIVATE(channelId, options) + : bot.constants.routes.THREAD_ARCHIVED_PUBLIC(channelId, options); - if (options.before) url += `before=${new Date(options.before).toISOString()}`; - if (options.limit) url += `&limit=${options.limit}`; - } const result = (await bot.rest.runMethod( bot.rest, "get", url, )); + return { threads: new Collection( result.threads.map((t) => { diff --git a/helpers/channels/threads/getThreadMember.ts b/helpers/channels/threads/getThreadMember.ts index 6f2fd7654..3b73cedd5 100644 --- a/helpers/channels/threads/getThreadMember.ts +++ b/helpers/channels/threads/getThreadMember.ts @@ -6,7 +6,7 @@ export async function getThreadMember(bot: Bot, threadId: bigint, userId: bigint const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.THREAD_USER(threadId, userId), + bot.constants.routes.THREAD_USER(threadId, userId), ); return { diff --git a/helpers/channels/threads/getThreadMembers.ts b/helpers/channels/threads/getThreadMembers.ts index 6200935f8..6d7369787 100644 --- a/helpers/channels/threads/getThreadMembers.ts +++ b/helpers/channels/threads/getThreadMembers.ts @@ -7,7 +7,7 @@ export async function getThreadMembers(bot: Bot, threadId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.THREAD_MEMBERS(threadId), + bot.constants.routes.THREAD_MEMBERS(threadId), ); // return result; diff --git a/helpers/channels/threads/joinThread.ts b/helpers/channels/threads/joinThread.ts index 17429e042..7a51873af 100644 --- a/helpers/channels/threads/joinThread.ts +++ b/helpers/channels/threads/joinThread.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../../bot.ts"; /** Adds the bot to the thread. Cannot join an archived thread. */ export async function joinThread(bot: Bot, threadId: bigint) { - await bot.rest.runMethod(bot.rest, "put", bot.constants.endpoints.THREAD_ME(threadId)); + await bot.rest.runMethod(bot.rest, "put", bot.constants.routes.THREAD_ME(threadId)); } diff --git a/helpers/channels/threads/leaveThread.ts b/helpers/channels/threads/leaveThread.ts index 1fe3a611a..8a6f57758 100644 --- a/helpers/channels/threads/leaveThread.ts +++ b/helpers/channels/threads/leaveThread.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../../bot.ts"; /** Removes the bot from a thread. Requires the thread is not archived. */ export async function leaveThread(bot: Bot, threadId: bigint) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.THREAD_ME(threadId)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.THREAD_ME(threadId)); } diff --git a/helpers/channels/threads/removeThreadMember.ts b/helpers/channels/threads/removeThreadMember.ts index 3cd128a00..e2d14868e 100644 --- a/helpers/channels/threads/removeThreadMember.ts +++ b/helpers/channels/threads/removeThreadMember.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../../bot.ts"; /** Removes a user from a thread. Requires the MANAGE_THREADS permission or that you are the creator of the thread. Also requires the thread is not archived. */ export async function removeThreadMember(bot: Bot, threadId: bigint, userId: bigint) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.THREAD_USER(threadId, userId)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.THREAD_USER(threadId, userId)); } diff --git a/helpers/channels/threads/startThreadWithMessage.ts b/helpers/channels/threads/startThreadWithMessage.ts index 44dbbff84..baee4b936 100644 --- a/helpers/channels/threads/startThreadWithMessage.ts +++ b/helpers/channels/threads/startThreadWithMessage.ts @@ -11,7 +11,7 @@ export async function startThreadWithMessage( const result = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.THREAD_START_PUBLIC(channelId, messageId), + bot.constants.routes.THREAD_START_PUBLIC(channelId, messageId), { name: options.name, auto_archive_duration: options.autoArchiveDuration, diff --git a/helpers/channels/threads/startThreadWithoutMessage.ts b/helpers/channels/threads/startThreadWithoutMessage.ts index 556467763..53d3b2576 100644 --- a/helpers/channels/threads/startThreadWithoutMessage.ts +++ b/helpers/channels/threads/startThreadWithoutMessage.ts @@ -7,7 +7,7 @@ export async function startThreadWithoutMessage(bot: Bot, channelId: bigint, opt const result = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.THREAD_START_PRIVATE(channelId), + bot.constants.routes.THREAD_START_PRIVATE(channelId), { name: options.name, auto_archive_duration: options.autoArchiveDuration, diff --git a/helpers/channels/updateStageInstance.ts b/helpers/channels/updateStageInstance.ts index c0c8d3502..4ad25d3b1 100644 --- a/helpers/channels/updateStageInstance.ts +++ b/helpers/channels/updateStageInstance.ts @@ -11,7 +11,7 @@ export async function updateStageInstance( const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.STAGE_INSTANCE(channelId), + bot.constants.routes.STAGE_INSTANCE(channelId), { topic: data.topic, }, diff --git a/helpers/channels/updateVoiceState.ts b/helpers/channels/updateVoiceState.ts index 7b220a534..ded3eb8ea 100644 --- a/helpers/channels/updateVoiceState.ts +++ b/helpers/channels/updateVoiceState.ts @@ -11,7 +11,7 @@ import type { Bot } from "../../bot.ts"; * - When suppressed, the user will have their `request_to_speak_timestamp` removed. */ export async function updateBotVoiceState(bot: Bot, guildId: bigint, options: UpdateSelfVoiceState) { - await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.UPDATE_VOICE_STATE(guildId), { + await bot.rest.runMethod(bot.rest, "patch", bot.constants.routes.UPDATE_VOICE_STATE(guildId), { channel_id: options.channelId, suppress: options.suppress, request_to_speak_timestamp: options.requestToSpeakTimestamp @@ -35,7 +35,7 @@ export async function updateUserVoiceState(bot: Bot, guildId: bigint, options: U await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.UPDATE_VOICE_STATE(guildId, options.userId), + bot.constants.routes.UPDATE_VOICE_STATE(guildId, options.userId), { channel_id: options.channelId, suppress: options.suppress, diff --git a/helpers/discovery/addDiscoverySubcategory.ts b/helpers/discovery/addDiscoverySubcategory.ts index 05fdf9885..6073121d0 100644 --- a/helpers/discovery/addDiscoverySubcategory.ts +++ b/helpers/discovery/addDiscoverySubcategory.ts @@ -6,6 +6,6 @@ export async function addDiscoverySubcategory(bot: Bot, guildId: bigint, categor await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId), + bot.constants.routes.DISCOVERY_SUBCATEGORY(guildId, categoryId), ); } diff --git a/helpers/discovery/editDiscovery.ts b/helpers/discovery/editDiscovery.ts index 86b9e0c88..fe8048065 100644 --- a/helpers/discovery/editDiscovery.ts +++ b/helpers/discovery/editDiscovery.ts @@ -6,7 +6,7 @@ export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuild const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.DISCOVERY_METADATA(guildId), + bot.constants.routes.DISCOVERY_METADATA(guildId), { primary_category_id: data.primaryCategoryId, keywords: data.keywords, diff --git a/helpers/discovery/getDiscovery.ts b/helpers/discovery/getDiscovery.ts index fe3fa154f..4d82b5940 100644 --- a/helpers/discovery/getDiscovery.ts +++ b/helpers/discovery/getDiscovery.ts @@ -6,7 +6,7 @@ export async function getDiscovery(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.DISCOVERY_METADATA(guildId), + bot.constants.routes.DISCOVERY_METADATA(guildId), ); return { diff --git a/helpers/discovery/getDiscoveryCategories.ts b/helpers/discovery/getDiscoveryCategories.ts index 81059cd26..8bbcfebb3 100644 --- a/helpers/discovery/getDiscoveryCategories.ts +++ b/helpers/discovery/getDiscoveryCategories.ts @@ -7,7 +7,7 @@ export async function getDiscoveryCategories(bot: Bot) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.DISCOVERY_CATEGORIES(), + bot.constants.routes.DISCOVERY_CATEGORIES(), ); return new Collection( diff --git a/helpers/discovery/removeDiscoverySubcategory.ts b/helpers/discovery/removeDiscoverySubcategory.ts index eba432147..ac7102fc9 100644 --- a/helpers/discovery/removeDiscoverySubcategory.ts +++ b/helpers/discovery/removeDiscoverySubcategory.ts @@ -5,6 +5,6 @@ export async function removeDiscoverySubcategory(bot: Bot, guildId: bigint, cate await bot.rest.runMethod( bot.rest, "delete", - bot.constants.endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId), + bot.constants.routes.DISCOVERY_SUBCATEGORY(guildId, categoryId), ); } diff --git a/helpers/discovery/validDiscoveryTerm.ts b/helpers/discovery/validDiscoveryTerm.ts index 40c94cf7b..1d6997126 100644 --- a/helpers/discovery/validDiscoveryTerm.ts +++ b/helpers/discovery/validDiscoveryTerm.ts @@ -5,7 +5,7 @@ export async function validDiscoveryTerm(bot: Bot, term: string) { const result = await bot.rest.runMethod( bot.rest, "get", - `${bot.constants.endpoints.DISCOVERY_VALID_TERM()}?term=${term}`, + bot.constants.routes.DISCOVERY_VALID_TERM(term), ); return result.valid; diff --git a/helpers/emojis/createEmoji.ts b/helpers/emojis/createEmoji.ts index 4efe2dcea..d21f32d93 100644 --- a/helpers/emojis/createEmoji.ts +++ b/helpers/emojis/createEmoji.ts @@ -10,7 +10,7 @@ export async function createEmoji(bot: Bot, guildId: bigint, options: CreateGuil const emoji = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.GUILD_EMOJIS(guildId), + bot.constants.routes.GUILD_EMOJIS(guildId), { name: options.name, image: options.image, diff --git a/helpers/emojis/deleteEmoji.ts b/helpers/emojis/deleteEmoji.ts index cc77e6c88..92325e844 100644 --- a/helpers/emojis/deleteEmoji.ts +++ b/helpers/emojis/deleteEmoji.ts @@ -2,7 +2,7 @@ import type { Bot } from "../../bot.ts"; /** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns 204 No Content on success. */ export async function deleteEmoji(bot: Bot, guildId: bigint, id: bigint, reason?: string) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.GUILD_EMOJI(guildId, id), { + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.GUILD_EMOJI(guildId, id), { reason, }); } diff --git a/helpers/emojis/editEmoji.ts b/helpers/emojis/editEmoji.ts index 3928ecdfc..d746e551c 100644 --- a/helpers/emojis/editEmoji.ts +++ b/helpers/emojis/editEmoji.ts @@ -6,7 +6,7 @@ export async function editEmoji(bot: Bot, guildId: bigint, id: bigint, options: const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.GUILD_EMOJI(guildId, id), + bot.constants.routes.GUILD_EMOJI(guildId, id), { name: options.name, // NEED TERNARY TO SUPPORT NULL AS VALID diff --git a/helpers/emojis/getEmoji.ts b/helpers/emojis/getEmoji.ts index 000ccc338..14aa995c7 100644 --- a/helpers/emojis/getEmoji.ts +++ b/helpers/emojis/getEmoji.ts @@ -8,7 +8,7 @@ export async function getEmoji(bot: Bot, guildId: bigint, emojiId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_EMOJI(guildId, emojiId), + bot.constants.routes.GUILD_EMOJI(guildId, emojiId), ); return bot.transformers.emoji(bot, result); diff --git a/helpers/emojis/getEmojis.ts b/helpers/emojis/getEmojis.ts index b011032bd..9ae389f46 100644 --- a/helpers/emojis/getEmojis.ts +++ b/helpers/emojis/getEmojis.ts @@ -9,7 +9,7 @@ export async function getEmojis(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_EMOJIS(guildId), + bot.constants.routes.GUILD_EMOJIS(guildId), ); return new Collection(result.map((e) => [bot.transformers.snowflake(e.id!), bot.transformers.emoji(bot, e)])); diff --git a/helpers/guilds/createGuild.ts b/helpers/guilds/createGuild.ts index 0f2582ef9..03e6114f3 100644 --- a/helpers/guilds/createGuild.ts +++ b/helpers/guilds/createGuild.ts @@ -11,7 +11,7 @@ import { /** 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(bot: Bot, options: CreateGuild) { - const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.GUILDS(), { + const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.routes.GUILDS(), { name: options.name, afk_channel_id: options.afkChannelId, afk_timeout: options.afkTimeout, diff --git a/helpers/guilds/deleteGuild.ts b/helpers/guilds/deleteGuild.ts index 45b0e1fb5..0c07eb316 100644 --- a/helpers/guilds/deleteGuild.ts +++ b/helpers/guilds/deleteGuild.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts"; /** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */ export async function deleteGuild(bot: Bot, guildId: bigint) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.GUILDS_BASE(guildId)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.GUILD(guildId)); } diff --git a/helpers/guilds/editGuild.ts b/helpers/guilds/editGuild.ts index 58d4fd83e..748a52611 100644 --- a/helpers/guilds/editGuild.ts +++ b/helpers/guilds/editGuild.ts @@ -25,7 +25,7 @@ export async function editGuild(bot: Bot, guildId: bigint, options: ModifyGuild, const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.GUILDS_BASE(guildId), + bot.constants.routes.GUILD(guildId), options, ); diff --git a/helpers/guilds/editWelcomeScreen.ts b/helpers/guilds/editWelcomeScreen.ts index c627711f8..907055c20 100644 --- a/helpers/guilds/editWelcomeScreen.ts +++ b/helpers/guilds/editWelcomeScreen.ts @@ -5,7 +5,7 @@ export async function editWelcomeScreen(bot: Bot, guildId: bigint, options: Modi const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId), + bot.constants.routes.GUILD_WELCOME_SCREEN(guildId), { enabled: options.enabled, welcome_screen: options.welcomeScreen?.map((welcomeScreen) => ({ diff --git a/helpers/guilds/editWidget.ts b/helpers/guilds/editWidget.ts index 2e88dbb16..e72c0e8df 100644 --- a/helpers/guilds/editWidget.ts +++ b/helpers/guilds/editWidget.ts @@ -6,7 +6,7 @@ export async function editWidget(bot: Bot, guildId: bigint, enabled: boolean, ch const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.GUILD_WIDGET(guildId), + bot.constants.routes.GUILD_WIDGET(guildId), { enabled, channel_id: channelId, diff --git a/helpers/guilds/getAuditLogs.ts b/helpers/guilds/getAuditLogs.ts index 995701b8d..e7a2b336e 100644 --- a/helpers/guilds/getAuditLogs.ts +++ b/helpers/guilds/getAuditLogs.ts @@ -6,19 +6,10 @@ import { AuditLogEvents } from "../../types/shared.ts"; export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuildAuditLog) { if (options?.limit) options.limit = options.limit >= 1 && options.limit <= 100 ? options.limit : 50; - let url = bot.constants.endpoints.GUILD_AUDIT_LOGS(guildId); - if (options) { - url += "?"; - - if (options.actionType) url += `action_type=${options.actionType}`; - if (options.before) url += `&before=${options.before}`; - if (options.limit) url += `&limit=${options.limit}`; - if (options.userId) url += `&user_id=${options.userId}`; - } const auditlog = await bot.rest.runMethod( bot.rest, "get", - url, + bot.constants.routes.GUILD_AUDIT_LOGS(guildId, options), ); return { diff --git a/helpers/guilds/getAvailableVoiceRegions.ts b/helpers/guilds/getAvailableVoiceRegions.ts index 8b9a84be6..ad9f3a6ee 100644 --- a/helpers/guilds/getAvailableVoiceRegions.ts +++ b/helpers/guilds/getAvailableVoiceRegions.ts @@ -7,7 +7,7 @@ export async function getAvailableVoiceRegions(bot: Bot) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.VOICE_REGIONS(), + bot.constants.routes.VOICE_REGIONS(), ); return new Collection( diff --git a/helpers/guilds/getBan.ts b/helpers/guilds/getBan.ts index 6b0348968..a9e109498 100644 --- a/helpers/guilds/getBan.ts +++ b/helpers/guilds/getBan.ts @@ -6,7 +6,7 @@ export async function getBan(bot: Bot, guildId: bigint, memberId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_BAN(guildId, memberId), + bot.constants.routes.GUILD_BAN(guildId, memberId), ); return { diff --git a/helpers/guilds/getBans.ts b/helpers/guilds/getBans.ts index 2f5371909..7f79086d0 100644 --- a/helpers/guilds/getBans.ts +++ b/helpers/guilds/getBans.ts @@ -5,17 +5,11 @@ import { User } from "../../transformers/member.ts"; /** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */ export async function getBans(bot: Bot, guildId: bigint, options?: GetBans) { - let url = bot.constants.endpoints.GUILD_BANS(guildId); - - if (options) { - url += "?"; - - if (options.limit) url += `limit=${options.limit}`; - if (options.after) url += `&after=${options.after}`; - if (options.before) url += `&before=${options.before}`; - } - - const results = await bot.rest.runMethod(bot.rest, "get", url); + const results = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.routes.GUILD_BANS(guildId, options), + ); return new Collection( results.map((res) => [ diff --git a/helpers/guilds/getGuild.ts b/helpers/guilds/getGuild.ts index df086cb64..ecc068255 100644 --- a/helpers/guilds/getGuild.ts +++ b/helpers/guilds/getGuild.ts @@ -15,7 +15,7 @@ export async function getGuild( const result = await bot.rest.runMethod( bot.rest, "get", - `${bot.constants.endpoints.GUILDS_BASE(guildId)}?with_counts=${options.counts ?? false}`, + bot.constants.routes.GUILD(guildId, options.counts), ); return bot.transformers.guild(bot, { diff --git a/helpers/guilds/getGuildPreview.ts b/helpers/guilds/getGuildPreview.ts index 17e44e7b4..e34b31237 100644 --- a/helpers/guilds/getGuildPreview.ts +++ b/helpers/guilds/getGuildPreview.ts @@ -6,7 +6,7 @@ export async function getGuildPreview(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_PREVIEW(guildId), + bot.constants.routes.GUILD_PREVIEW(guildId), ); return { diff --git a/helpers/guilds/getPruneCount.ts b/helpers/guilds/getPruneCount.ts index c1add1883..9e9549eb5 100644 --- a/helpers/guilds/getPruneCount.ts +++ b/helpers/guilds/getPruneCount.ts @@ -5,19 +5,10 @@ export async function getPruneCount(bot: Bot, guildId: bigint, options?: GetGuil if (options?.days && options.days < 1) throw new Error(bot.constants.Errors.PRUNE_MIN_DAYS); if (options?.days && options.days > 30) throw new Error(bot.constants.Errors.PRUNE_MAX_DAYS); - let url = bot.constants.endpoints.GUILD_PRUNE(guildId); - - if (options) { - url += "?"; - - if (options.days) url += `days=${options.days}`; - if (options.includeRoles) url += `&include_roles=${options.includeRoles}`; - } - const result = await bot.rest.runMethod( bot.rest, "get", - url, + bot.constants.routes.GUILD_PRUNE(guildId), ); return result.pruned as number; diff --git a/helpers/guilds/getVanityUrl.ts b/helpers/guilds/getVanityUrl.ts index 650e3bb16..242678e59 100644 --- a/helpers/guilds/getVanityUrl.ts +++ b/helpers/guilds/getVanityUrl.ts @@ -6,7 +6,7 @@ export async function getVanityUrl(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod>( bot.rest, "get", - bot.constants.endpoints.GUILD_VANITY_URL(guildId), + bot.constants.routes.GUILD_VANITY_URL(guildId), ); return { diff --git a/helpers/guilds/getVoiceRegions.ts b/helpers/guilds/getVoiceRegions.ts index 96f7225fd..7554f429b 100644 --- a/helpers/guilds/getVoiceRegions.ts +++ b/helpers/guilds/getVoiceRegions.ts @@ -7,7 +7,7 @@ export async function getVoiceRegions(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_REGIONS(guildId), + bot.constants.routes.GUILD_REGIONS(guildId), ); return new Collection( diff --git a/helpers/guilds/getWelcomeScreen.ts b/helpers/guilds/getWelcomeScreen.ts index 1aa80a304..8970273e5 100644 --- a/helpers/guilds/getWelcomeScreen.ts +++ b/helpers/guilds/getWelcomeScreen.ts @@ -6,7 +6,7 @@ export async function getWelcomeScreen(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId), + bot.constants.routes.GUILD_WELCOME_SCREEN(guildId), ); return bot.transformers.welcomeScreen(bot, result); diff --git a/helpers/guilds/getWidget.ts b/helpers/guilds/getWidget.ts index 4ad6a2219..55ff153e7 100644 --- a/helpers/guilds/getWidget.ts +++ b/helpers/guilds/getWidget.ts @@ -6,7 +6,7 @@ export async function getWidget(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - `${bot.constants.endpoints.GUILD_WIDGET(guildId)}.json`, + bot.constants.routes.GUILD_WIDGET_JSON(guildId), ); return bot.transformers.widget(bot, result); diff --git a/helpers/guilds/getWidgetImageUrl.ts b/helpers/guilds/getWidgetImageUrl.ts index b1a604eb3..75dd6e385 100644 --- a/helpers/guilds/getWidgetImageUrl.ts +++ b/helpers/guilds/getWidgetImageUrl.ts @@ -2,7 +2,7 @@ import type { Bot } from "../../bot.ts"; /** Returns the widget image URL for the guild. */ export async function getWidgetImageURL(bot: Bot, guildId: bigint, options?: GetGuildWidgetImageQuery) { - return `${bot.constants.endpoints.GUILD_WIDGET(guildId)}.png?style=${options?.style ?? "shield"}`; + return bot.constants.routes.GUILD_WIDGET_IMAGE(guildId, options?.style); } /** https://discord.com/developers/docs/resources/guild#get-guild-widget-image-query-string-params */ diff --git a/helpers/guilds/getWidgetSettings.ts b/helpers/guilds/getWidgetSettings.ts index ea76b9a4e..38d841464 100644 --- a/helpers/guilds/getWidgetSettings.ts +++ b/helpers/guilds/getWidgetSettings.ts @@ -6,7 +6,7 @@ export async function getWidgetSettings(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_WIDGET(guildId), + bot.constants.routes.GUILD_WIDGET(guildId), ); return bot.transformers.widgetSettings(bot, result); diff --git a/helpers/guilds/guildBannerUrl.ts b/helpers/guilds/guildBannerUrl.ts index d94231c6b..b00340dd3 100644 --- a/helpers/guilds/guildBannerUrl.ts +++ b/helpers/guilds/guildBannerUrl.ts @@ -13,7 +13,7 @@ export function guildBannerURL( ) { return options.banner ? bot.utils.formatImageURL( - bot.constants.endpoints.GUILD_BANNER( + bot.constants.routes.GUILD_BANNER( id, typeof options.banner === "string" ? options.banner : bot.utils.iconBigintToHash(options.banner), ), diff --git a/helpers/guilds/guildIconUrl.ts b/helpers/guilds/guildIconUrl.ts index a4c7dbe9c..16d7686ad 100644 --- a/helpers/guilds/guildIconUrl.ts +++ b/helpers/guilds/guildIconUrl.ts @@ -13,7 +13,7 @@ export function guildIconURL( ) { return icon ? bot.utils.formatImageURL( - bot.constants.endpoints.GUILD_ICON( + bot.constants.routes.GUILD_ICON( id, typeof icon === "string" ? icon : bot.utils.iconBigintToHash(icon), ), diff --git a/helpers/guilds/guildSplashUrl.ts b/helpers/guilds/guildSplashUrl.ts index 9d95c31af..aaa9114be 100644 --- a/helpers/guilds/guildSplashUrl.ts +++ b/helpers/guilds/guildSplashUrl.ts @@ -13,7 +13,7 @@ export function guildSplashURL( ) { return splash ? bot.utils.formatImageURL( - bot.constants.endpoints.GUILD_SPLASH( + bot.constants.routes.GUILD_SPLASH( id, typeof splash === "string" ? splash : bot.utils.iconBigintToHash(splash), ), diff --git a/helpers/guilds/leaveGuild.ts b/helpers/guilds/leaveGuild.ts index fade59ee2..d8c0f88b0 100644 --- a/helpers/guilds/leaveGuild.ts +++ b/helpers/guilds/leaveGuild.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts"; /** Leave a guild */ export async function leaveGuild(bot: Bot, guildId: bigint) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.GUILD_LEAVE(guildId)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.GUILD_LEAVE(guildId)); } diff --git a/helpers/guilds/scheduledEvents/createScheduledEvent.ts b/helpers/guilds/scheduledEvents/createScheduledEvent.ts index 8c4989831..5a346a11f 100644 --- a/helpers/guilds/scheduledEvents/createScheduledEvent.ts +++ b/helpers/guilds/scheduledEvents/createScheduledEvent.ts @@ -29,7 +29,7 @@ export async function createScheduledEvent(bot: Bot, guildId: bigint, options: C const event = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.GUILD_SCHEDULED_EVENTS(guildId), + bot.constants.routes.GUILD_SCHEDULED_EVENTS(guildId), { channel_id: options.channelId?.toString(), entity_metadata: options.location ? { location: options.location } : undefined, diff --git a/helpers/guilds/scheduledEvents/deleteScheduledEvent.ts b/helpers/guilds/scheduledEvents/deleteScheduledEvent.ts index 748499ffc..0b74bd1ee 100644 --- a/helpers/guilds/scheduledEvents/deleteScheduledEvent.ts +++ b/helpers/guilds/scheduledEvents/deleteScheduledEvent.ts @@ -5,6 +5,6 @@ export async function deleteScheduledEvent(bot: Bot, guildId: bigint, eventId: b await bot.rest.runMethod( bot.rest, "delete", - bot.constants.endpoints.GUILD_SCHEDULED_EVENT(guildId, eventId), + bot.constants.routes.GUILD_SCHEDULED_EVENT(guildId, eventId), ); } diff --git a/helpers/guilds/scheduledEvents/editScheduledEvent.ts b/helpers/guilds/scheduledEvents/editScheduledEvent.ts index ae46044ce..d21e06655 100644 --- a/helpers/guilds/scheduledEvents/editScheduledEvent.ts +++ b/helpers/guilds/scheduledEvents/editScheduledEvent.ts @@ -25,7 +25,7 @@ export async function editScheduledEvent( const event = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.GUILD_SCHEDULED_EVENT(guildId, eventId), + bot.constants.routes.GUILD_SCHEDULED_EVENT(guildId, eventId), { channel_id: options.channelId === null ? null : options.channelId?.toString(), entity_metadata: options.location ? { location: options.location } : undefined, diff --git a/helpers/guilds/scheduledEvents/getScheduledEvent.ts b/helpers/guilds/scheduledEvents/getScheduledEvent.ts index 5cf75d56d..bb8d9ad05 100644 --- a/helpers/guilds/scheduledEvents/getScheduledEvent.ts +++ b/helpers/guilds/scheduledEvents/getScheduledEvent.ts @@ -11,9 +11,7 @@ export async function getScheduledEvent( const event = await bot.rest.runMethod( bot.rest, "get", - `${bot.constants.endpoints.GUILD_SCHEDULED_EVENT(guildId, eventId)}?with_user_count=${ - options?.withUserCount ?? false - }`, + bot.constants.routes.GUILD_SCHEDULED_EVENT(guildId, eventId, options?.withUserCount), ); return bot.transformers.scheduledEvent(bot, event); diff --git a/helpers/guilds/scheduledEvents/getScheduledEventUsers.ts b/helpers/guilds/scheduledEvents/getScheduledEventUsers.ts index 21b9db842..90fb6ad74 100644 --- a/helpers/guilds/scheduledEvents/getScheduledEventUsers.ts +++ b/helpers/guilds/scheduledEvents/getScheduledEventUsers.ts @@ -23,7 +23,7 @@ export async function getScheduledEventUsers( ): Promise< Collection | Collection > { - let url = bot.constants.endpoints.GUILD_SCHEDULED_EVENT_USERS(guildId, eventId); + let url = bot.constants.routes.GUILD_SCHEDULED_EVENT_USERS(guildId, eventId, options); if (options) { url = "?"; diff --git a/helpers/guilds/scheduledEvents/getScheduledEvents.ts b/helpers/guilds/scheduledEvents/getScheduledEvents.ts index fd4c9d9cf..b285a805e 100644 --- a/helpers/guilds/scheduledEvents/getScheduledEvents.ts +++ b/helpers/guilds/scheduledEvents/getScheduledEvents.ts @@ -8,7 +8,7 @@ export async function getScheduledEvents(bot: Bot, guildId: bigint, options?: Ge const events = await bot.rest.runMethod( bot.rest, "get", - `${bot.constants.endpoints.GUILD_SCHEDULED_EVENTS(guildId)}?with_user_count=${options?.withUserCount ?? false}`, + bot.constants.routes.GUILD_SCHEDULED_EVENTS(guildId, options?.withUserCount), ); return new Collection( diff --git a/helpers/integrations/deleteIntegration.ts b/helpers/integrations/deleteIntegration.ts index 5be3de2af..4062b2034 100644 --- a/helpers/integrations/deleteIntegration.ts +++ b/helpers/integrations/deleteIntegration.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts"; /** Delete the attached integration object for the guild with this id. Requires MANAGE_GUILD permission. */ export async function deleteIntegration(bot: Bot, guildId: bigint, id: bigint) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.GUILD_INTEGRATION(guildId, id)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.GUILD_INTEGRATION(guildId, id)); } diff --git a/helpers/integrations/getIntegrations.ts b/helpers/integrations/getIntegrations.ts index b8092a316..9f430d773 100644 --- a/helpers/integrations/getIntegrations.ts +++ b/helpers/integrations/getIntegrations.ts @@ -7,7 +7,7 @@ export async function getIntegrations(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_INTEGRATIONS(guildId), + bot.constants.routes.GUILD_INTEGRATIONS(guildId), ); return new Collection( diff --git a/helpers/interactions/commands/createApplicationCommand.ts b/helpers/interactions/commands/createApplicationCommand.ts index 3ad381eae..ed8fd1160 100644 --- a/helpers/interactions/commands/createApplicationCommand.ts +++ b/helpers/interactions/commands/createApplicationCommand.ts @@ -23,8 +23,8 @@ export async function createApplicationCommand( bot.rest, "post", guildId - ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) - : bot.constants.endpoints.COMMANDS(bot.applicationId), + ? bot.constants.routes.COMMANDS_GUILD(bot.applicationId, guildId) + : bot.constants.routes.COMMANDS(bot.applicationId), isContextApplicationCommand(options) ? { name: options.name, name_localizations: options.nameLocalizations, type: options.type } : { diff --git a/helpers/interactions/commands/deleteApplicationCommand.ts b/helpers/interactions/commands/deleteApplicationCommand.ts index 874083535..793253993 100644 --- a/helpers/interactions/commands/deleteApplicationCommand.ts +++ b/helpers/interactions/commands/deleteApplicationCommand.ts @@ -6,7 +6,7 @@ export async function deleteApplicationCommand(bot: Bot, id: bigint, guildId?: b bot.rest, "delete", guildId - ? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, guildId, id) - : bot.constants.endpoints.COMMANDS_ID(bot.applicationId, id), + ? bot.constants.routes.COMMANDS_GUILD_ID(bot.applicationId, guildId, id) + : bot.constants.routes.COMMANDS_ID(bot.applicationId, id), ); } diff --git a/helpers/interactions/commands/deleteInteractionResponse.ts b/helpers/interactions/commands/deleteInteractionResponse.ts index e6de957e9..ac3f50317 100644 --- a/helpers/interactions/commands/deleteInteractionResponse.ts +++ b/helpers/interactions/commands/deleteInteractionResponse.ts @@ -6,7 +6,7 @@ export async function deleteInteractionResponse(bot: Bot, token: string, message bot.rest, "delete", messageId - ? bot.constants.endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(bot.applicationId, token, messageId) - : bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token), + ? bot.constants.routes.INTERACTION_ID_TOKEN_MESSAGE_ID(bot.applicationId, token, messageId) + : bot.constants.routes.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token), ); } diff --git a/helpers/interactions/commands/editApplicationCommandPermissions.ts b/helpers/interactions/commands/editApplicationCommandPermissions.ts index a06af3e1b..63cce29a2 100644 --- a/helpers/interactions/commands/editApplicationCommandPermissions.ts +++ b/helpers/interactions/commands/editApplicationCommandPermissions.ts @@ -14,7 +14,7 @@ export async function editApplicationCommandPermissions( const result = await bot.rest.runMethod( bot.rest, "put", - bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId), + bot.constants.routes.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId), { permissions: options, }, diff --git a/helpers/interactions/commands/editInteractionResponse.ts b/helpers/interactions/commands/editInteractionResponse.ts index e4df9e9df..9b9da11dc 100644 --- a/helpers/interactions/commands/editInteractionResponse.ts +++ b/helpers/interactions/commands/editInteractionResponse.ts @@ -15,8 +15,8 @@ export async function editInteractionResponse( bot.rest, "patch", options.messageId - ? bot.constants.endpoints.WEBHOOK_MESSAGE(bot.applicationId, token, options.messageId) - : bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token), + ? bot.constants.routes.WEBHOOK_MESSAGE(bot.applicationId, token, options.messageId) + : bot.constants.routes.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token), { content: options.content, embeds: options.embeds?.map((embed) => bot.transformers.reverse.embed(bot, embed)), diff --git a/helpers/interactions/commands/getApplicationCommand.ts b/helpers/interactions/commands/getApplicationCommand.ts index f50dd5f20..25d69036d 100644 --- a/helpers/interactions/commands/getApplicationCommand.ts +++ b/helpers/interactions/commands/getApplicationCommand.ts @@ -3,20 +3,17 @@ import { DiscordApplicationCommand } from "../../../types/discord.ts"; /** Fetches the global command for the given Id. If a guildId is provided, the guild command will be fetched. */ export async function getApplicationCommand(bot: Bot, commandId: bigint, options?: GetApplicationCommand) { - let url = `${ - options?.guildId - ? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, options.guildId, commandId) - : bot.constants.endpoints.COMMANDS_ID(bot.applicationId, commandId) - }?`; - - if (options?.withLocalizations !== undefined) { - url += `with_localizations=${options.withLocalizations}`; - } - const result = await bot.rest.runMethod( bot.rest, "get", - url, + options?.guildId + ? bot.constants.routes.COMMANDS_GUILD_ID( + bot.applicationId, + options.guildId, + commandId, + options?.withLocalizations, + ) + : bot.constants.routes.COMMANDS_ID(bot.applicationId, commandId, options?.withLocalizations), ); return bot.transformers.applicationCommand(bot, result); diff --git a/helpers/interactions/commands/getApplicationCommandPermission.ts b/helpers/interactions/commands/getApplicationCommandPermission.ts index 1b8908c98..a6b40daa6 100644 --- a/helpers/interactions/commands/getApplicationCommandPermission.ts +++ b/helpers/interactions/commands/getApplicationCommandPermission.ts @@ -6,7 +6,7 @@ export async function getApplicationCommandPermission(bot: Bot, guildId: bigint, const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId), + bot.constants.routes.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId), ); return bot.transformers.applicationCommandPermission(bot, result); diff --git a/helpers/interactions/commands/getApplicationCommandPermissions.ts b/helpers/interactions/commands/getApplicationCommandPermissions.ts index f90016f46..463c95ce1 100644 --- a/helpers/interactions/commands/getApplicationCommandPermissions.ts +++ b/helpers/interactions/commands/getApplicationCommandPermissions.ts @@ -7,7 +7,7 @@ export async function getApplicationCommandPermissions(bot: Bot, guildId: bigint const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId), + bot.constants.routes.COMMANDS_PERMISSIONS(bot.applicationId, guildId), ); return new Collection( diff --git a/helpers/interactions/commands/getApplicationCommands.ts b/helpers/interactions/commands/getApplicationCommands.ts index a3289f28a..91d078a67 100644 --- a/helpers/interactions/commands/getApplicationCommands.ts +++ b/helpers/interactions/commands/getApplicationCommands.ts @@ -8,8 +8,8 @@ export async function getApplicationCommands(bot: Bot, guildId?: bigint) { bot.rest, "get", guildId - ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) - : bot.constants.endpoints.COMMANDS(bot.applicationId), + ? bot.constants.routes.COMMANDS_GUILD(bot.applicationId, guildId) + : bot.constants.routes.COMMANDS(bot.applicationId), ); return new Collection( diff --git a/helpers/interactions/commands/upsertApplicationCommand.ts b/helpers/interactions/commands/upsertApplicationCommand.ts index c433448d3..acd078be7 100644 --- a/helpers/interactions/commands/upsertApplicationCommand.ts +++ b/helpers/interactions/commands/upsertApplicationCommand.ts @@ -21,8 +21,8 @@ export async function upsertApplicationCommand( bot.rest, "patch", guildId - ? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, guildId, commandId) - : bot.constants.endpoints.COMMANDS_ID(bot.applicationId, commandId), + ? bot.constants.routes.COMMANDS_GUILD_ID(bot.applicationId, guildId, commandId) + : bot.constants.routes.COMMANDS_ID(bot.applicationId, commandId), isContextApplicationCommand(options) ? { name: options.name, diff --git a/helpers/interactions/commands/upsertApplicationCommands.ts b/helpers/interactions/commands/upsertApplicationCommands.ts index 2c9f2d968..97b94477d 100644 --- a/helpers/interactions/commands/upsertApplicationCommands.ts +++ b/helpers/interactions/commands/upsertApplicationCommands.ts @@ -23,8 +23,8 @@ export async function upsertApplicationCommands( bot.rest, "put", guildId - ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) - : bot.constants.endpoints.COMMANDS(bot.applicationId), + ? bot.constants.routes.COMMANDS_GUILD(bot.applicationId, guildId) + : bot.constants.routes.COMMANDS(bot.applicationId), options.map((option) => (isContextApplicationCommand(option) ? { name: option.name, diff --git a/helpers/interactions/followups/deleteFollowupMessage.ts b/helpers/interactions/followups/deleteFollowupMessage.ts index 918c1135e..3af1c10ec 100644 --- a/helpers/interactions/followups/deleteFollowupMessage.ts +++ b/helpers/interactions/followups/deleteFollowupMessage.ts @@ -5,6 +5,6 @@ export async function deleteFollowupMessage(bot: Bot, interactionToken: string, await bot.rest.runMethod( bot.rest, "delete", - bot.constants.endpoints.WEBHOOK_MESSAGE(bot.applicationId, interactionToken, messageId), + bot.constants.routes.WEBHOOK_MESSAGE(bot.applicationId, interactionToken, messageId), ); } diff --git a/helpers/interactions/followups/editFollowupMessage.ts b/helpers/interactions/followups/editFollowupMessage.ts index 02a309a1d..c14e211b9 100644 --- a/helpers/interactions/followups/editFollowupMessage.ts +++ b/helpers/interactions/followups/editFollowupMessage.ts @@ -13,7 +13,7 @@ export async function editFollowupMessage( const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.WEBHOOK_MESSAGE(bot.applicationId, interactionToken, messageId), + bot.constants.routes.WEBHOOK_MESSAGE(bot.applicationId, interactionToken, messageId), { content: options.content, embeds: options.embeds?.map((embed) => bot.transformers.reverse.embed(bot, embed)), diff --git a/helpers/interactions/followups/getFollowupMessage.ts b/helpers/interactions/followups/getFollowupMessage.ts index 937f7d1a2..4cff347e2 100644 --- a/helpers/interactions/followups/getFollowupMessage.ts +++ b/helpers/interactions/followups/getFollowupMessage.ts @@ -6,7 +6,7 @@ export async function getFollowupMessage(bot: Bot, interactionToken: string, mes const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.WEBHOOK_MESSAGE(bot.applicationId, interactionToken, messageId), + bot.constants.routes.WEBHOOK_MESSAGE(bot.applicationId, interactionToken, messageId), ); return bot.transformers.message(bot, result); diff --git a/helpers/interactions/getOriginalInteractionResponse.ts b/helpers/interactions/getOriginalInteractionResponse.ts index e06f767b2..a667ccc6f 100644 --- a/helpers/interactions/getOriginalInteractionResponse.ts +++ b/helpers/interactions/getOriginalInteractionResponse.ts @@ -6,7 +6,7 @@ export async function getOriginalInteractionResponse(bot: Bot, token: string) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token), + bot.constants.routes.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token), ); return bot.transformers.message(bot, result); diff --git a/helpers/interactions/sendInteractionResponse.ts b/helpers/interactions/sendInteractionResponse.ts index ec7220dee..6ac0d150d 100644 --- a/helpers/interactions/sendInteractionResponse.ts +++ b/helpers/interactions/sendInteractionResponse.ts @@ -100,7 +100,7 @@ export async function sendInteractionResponse( return await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.INTERACTION_ID_TOKEN(id, token), + bot.constants.routes.INTERACTION_ID_TOKEN(id, token), { type: options.type, data, @@ -113,7 +113,7 @@ export async function sendInteractionResponse( const result = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.WEBHOOK(bot.applicationId, token), + bot.constants.routes.WEBHOOK(bot.applicationId, token), { ...data, file: options.data.file }, ); diff --git a/helpers/invites/createInvite.ts b/helpers/invites/createInvite.ts index 4e2a3dfd5..d17b7837a 100644 --- a/helpers/invites/createInvite.ts +++ b/helpers/invites/createInvite.ts @@ -7,7 +7,7 @@ export async function createInvite(bot: Bot, channelId: bigint, options: CreateC const result = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.CHANNEL_INVITES(channelId), + bot.constants.routes.CHANNEL_INVITES(channelId), { max_age: options.maxAge, max_uses: options.maxUses, diff --git a/helpers/invites/deleteInvite.ts b/helpers/invites/deleteInvite.ts index 41ff820ae..c459c36ff 100644 --- a/helpers/invites/deleteInvite.ts +++ b/helpers/invites/deleteInvite.ts @@ -3,5 +3,5 @@ import { DiscordInviteMetadata } from "../../types/discord.ts"; /** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */ export async function deleteInvite(bot: Bot, inviteCode: string) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.INVITE(inviteCode)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.INVITE(inviteCode)); } diff --git a/helpers/invites/getChannelInvites.ts b/helpers/invites/getChannelInvites.ts index ba4c3e08e..580f22952 100644 --- a/helpers/invites/getChannelInvites.ts +++ b/helpers/invites/getChannelInvites.ts @@ -7,7 +7,7 @@ export async function getChannelInvites(bot: Bot, channelId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.CHANNEL_INVITES(channelId), + bot.constants.routes.CHANNEL_INVITES(channelId), ); return new Collection( diff --git a/helpers/invites/getInvite.ts b/helpers/invites/getInvite.ts index 0fab407ed..9fc59f147 100644 --- a/helpers/invites/getInvite.ts +++ b/helpers/invites/getInvite.ts @@ -3,19 +3,10 @@ import { DiscordInviteMetadata } from "../../types/discord.ts"; /** Returns an invite for the given code or throws an error if the invite doesn't exists. */ export async function getInvite(bot: Bot, inviteCode: string, options?: GetInvite) { - let url = bot.constants.endpoints.INVITE(inviteCode); - - if (options) { - url += "?"; - - if (options.withCounts) url += `with_counts=${options.withCounts}`; - if (options.withExpiration) url += `&with_expiration=${options.withExpiration}`; - if (options.scheduledEventId) url += `&guild_scheduled_event_id=${options.scheduledEventId}`; - } const result = await bot.rest.runMethod( bot.rest, "get", - url, + bot.constants.routes.INVITE(inviteCode, options), ); return { diff --git a/helpers/invites/getInvites.ts b/helpers/invites/getInvites.ts index 0c68f47b4..470bb9cc7 100644 --- a/helpers/invites/getInvites.ts +++ b/helpers/invites/getInvites.ts @@ -7,7 +7,7 @@ export async function getInvites(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_INVITES(guildId), + bot.constants.routes.GUILD_INVITES(guildId), ); return new Collection( diff --git a/helpers/members/avatarUrl.ts b/helpers/members/avatarUrl.ts index df0eb4c29..921d30650 100644 --- a/helpers/members/avatarUrl.ts +++ b/helpers/members/avatarUrl.ts @@ -13,14 +13,14 @@ export function avatarURL( ) { return options?.avatar ? bot.utils.formatImageURL( - bot.constants.endpoints.USER_AVATAR( + bot.constants.routes.USER_AVATAR( userId, typeof options?.avatar === "string" ? options.avatar : bot.utils.iconBigintToHash(options?.avatar), ), options?.size || 128, options?.format, ) - : bot.constants.endpoints.USER_DEFAULT_AVATAR(Number(discriminator) % 5); + : bot.constants.routes.USER_DEFAULT_AVATAR(Number(discriminator) % 5); } /** diff --git a/helpers/members/banMember.ts b/helpers/members/banMember.ts index 8e06d5dc4..fbaa77ec7 100644 --- a/helpers/members/banMember.ts +++ b/helpers/members/banMember.ts @@ -5,7 +5,7 @@ export async function banMember(bot: Bot, guildId: bigint, id: bigint, options?: await bot.rest.runMethod( bot.rest, "put", - bot.constants.endpoints.GUILD_BAN(guildId, id), + bot.constants.routes.GUILD_BAN(guildId, id), options ? { delete_message_days: options.deleteMessageDays, diff --git a/helpers/members/editBotNickname.ts b/helpers/members/editBotNickname.ts index 16e2db266..decc26af8 100644 --- a/helpers/members/editBotNickname.ts +++ b/helpers/members/editBotNickname.ts @@ -5,7 +5,7 @@ export async function editBotNickname(bot: Bot, guildId: bigint, options: { nick const response = await bot.rest.runMethod<{ nick: string }>( bot.rest, "patch", - bot.constants.endpoints.USER_NICK(guildId), + bot.constants.routes.USER_NICK(guildId), options, ); diff --git a/helpers/members/editMember.ts b/helpers/members/editMember.ts index c4ff45db0..7987c00e8 100644 --- a/helpers/members/editMember.ts +++ b/helpers/members/editMember.ts @@ -6,7 +6,7 @@ export async function editMember(bot: Bot, guildId: bigint, memberId: bigint, op const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.GUILD_MEMBER(guildId, memberId), + bot.constants.routes.GUILD_MEMBER(guildId, memberId), { nick: options.nick, roles: options.roles?.map((id) => id.toString()), diff --git a/helpers/members/getDmChannel.ts b/helpers/members/getDmChannel.ts index aec9a0faf..77c28507a 100644 --- a/helpers/members/getDmChannel.ts +++ b/helpers/members/getDmChannel.ts @@ -5,7 +5,7 @@ import { DiscordChannel } from "../../types/discord.ts"; export async function getDmChannel(bot: Bot, userId: bigint) { if (userId === bot.id) throw new Error(bot.constants.Errors.YOU_CAN_NOT_DM_THE_BOT_ITSELF); - const dmChannelData = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.USER_DM(), { + const dmChannelData = await bot.rest.runMethod(bot.rest, "post", bot.constants.routes.USER_DM(), { recipient_id: userId.toString(), }); diff --git a/helpers/members/getMember.ts b/helpers/members/getMember.ts index 8df9f8739..0a3015cd2 100644 --- a/helpers/members/getMember.ts +++ b/helpers/members/getMember.ts @@ -6,7 +6,7 @@ export async function getMember(bot: Bot, guildId: bigint, id: bigint) { const data = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_MEMBER(guildId, id), + bot.constants.routes.GUILD_MEMBER(guildId, id), ); return bot.transformers.member(bot, data, guildId, id); diff --git a/helpers/members/getMembers.ts b/helpers/members/getMembers.ts index f8ebe58c7..c022e88b2 100644 --- a/helpers/members/getMembers.ts +++ b/helpers/members/getMembers.ts @@ -2,20 +2,17 @@ import type { Bot } from "../../bot.ts"; import { DiscordMemberWithUser } from "../../types/discord.ts"; import { Collection } from "../../util/collection.ts"; +// TODO: make options optional /** * Highly recommended to **NOT** use this function to get members instead use fetchMembers(). * REST(this function): 50/s global(across all shards) rate limit with ALL requests this included * GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m. */ export async function getMembers(bot: Bot, guildId: bigint, options: ListGuildMembers) { - let url = `${bot.constants.endpoints.GUILD_MEMBERS(guildId)}?limit=${options.limit || 1000}`; - - if (options.after) url += `&after=${options.after}`; - const result = await bot.rest.runMethod( bot.rest, "get", - url, + bot.constants.routes.GUILD_MEMBERS(guildId, options), ); return new Collection( diff --git a/helpers/members/kickMember.ts b/helpers/members/kickMember.ts index d6145521b..4b86363ab 100644 --- a/helpers/members/kickMember.ts +++ b/helpers/members/kickMember.ts @@ -2,7 +2,7 @@ import { Bot } from "../../bot.ts"; /** Kick a member from the server */ export async function kickMember(bot: Bot, guildId: bigint, memberId: bigint, reason?: string) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.GUILD_MEMBER(guildId, memberId), { + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.GUILD_MEMBER(guildId, memberId), { reason, }); } diff --git a/helpers/members/pruneMembers.ts b/helpers/members/pruneMembers.ts index 4fc9d95f6..426e9c4be 100644 --- a/helpers/members/pruneMembers.ts +++ b/helpers/members/pruneMembers.ts @@ -12,7 +12,7 @@ export async function pruneMembers(bot: Bot, guildId: bigint, options: BeginGuil const result = await bot.rest.runMethod<{ pruned: number }>( bot.rest, "post", - bot.constants.endpoints.GUILD_PRUNE(guildId), + bot.constants.routes.GUILD_PRUNE(guildId), { days: options.days, compute_prune_count: options.computePruneCount, diff --git a/helpers/members/searchMembers.ts b/helpers/members/searchMembers.ts index 7287213bc..08953c9ed 100644 --- a/helpers/members/searchMembers.ts +++ b/helpers/members/searchMembers.ts @@ -20,14 +20,10 @@ export async function searchMembers( } } - let url = `${bot.constants.endpoints.GUILD_MEMBERS_SEARCH(guildId)}?query=${query}`; - - if (options?.limit) url += `&limit=${options?.limit}`; - const result = await bot.rest.runMethod( bot.rest, "get", - url, + bot.constants.routes.GUILD_MEMBERS_SEARCH(guildId, query, options), ); return new Collection( diff --git a/helpers/members/unbanMember.ts b/helpers/members/unbanMember.ts index 2dd874620..653b6c9a9 100644 --- a/helpers/members/unbanMember.ts +++ b/helpers/members/unbanMember.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts"; /** Remove the ban for a user. Requires BAN_MEMBERS permission */ export async function unbanMember(bot: Bot, guildId: bigint, id: bigint) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.GUILD_BAN(guildId, id)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.GUILD_BAN(guildId, id)); } diff --git a/helpers/messages/addReaction.ts b/helpers/messages/addReaction.ts index b67de8462..d28d2b749 100644 --- a/helpers/messages/addReaction.ts +++ b/helpers/messages/addReaction.ts @@ -11,7 +11,7 @@ export async function addReaction(bot: Bot, channelId: bigint, messageId: bigint await bot.rest.runMethod( bot.rest, "put", - bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, encodeURIComponent(reaction)), + bot.constants.routes.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction), {}, ); } diff --git a/helpers/messages/deleteMessage.ts b/helpers/messages/deleteMessage.ts index 4810ded3c..924fa195d 100644 --- a/helpers/messages/deleteMessage.ts +++ b/helpers/messages/deleteMessage.ts @@ -13,7 +13,7 @@ export async function deleteMessage( await bot.rest.runMethod( bot.rest, "delete", - bot.constants.endpoints.CHANNEL_MESSAGE(channelId, messageId), + bot.constants.routes.CHANNEL_MESSAGE(channelId, messageId), { reason }, ); } diff --git a/helpers/messages/deleteMessages.ts b/helpers/messages/deleteMessages.ts index 591ad79a8..1c85daaa5 100644 --- a/helpers/messages/deleteMessages.ts +++ b/helpers/messages/deleteMessages.ts @@ -10,7 +10,7 @@ export async function deleteMessages(bot: Bot, channelId: bigint, ids: bigint[], console.warn(`This endpoint only accepts a maximum of 100 messages. Deleting the first 100 message ids provided.`); } - await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.CHANNEL_BULK_DELETE(channelId), { + await bot.rest.runMethod(bot.rest, "post", bot.constants.routes.CHANNEL_BULK_DELETE(channelId), { messages: ids.splice(0, 100).map((id) => id.toString()), reason, }); diff --git a/helpers/messages/editMessage.ts b/helpers/messages/editMessage.ts index c93d87110..d071ab39c 100644 --- a/helpers/messages/editMessage.ts +++ b/helpers/messages/editMessage.ts @@ -10,7 +10,7 @@ export async function editMessage(bot: Bot, channelId: bigint, messageId: bigint const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.CHANNEL_MESSAGE(channelId, messageId), + bot.constants.routes.CHANNEL_MESSAGE(channelId, messageId), { content: content.content, embeds: content.embeds?.map((embed) => bot.transformers.reverse.embed(bot, embed)), diff --git a/helpers/messages/getMessage.ts b/helpers/messages/getMessage.ts index 55ed575c6..eded16751 100644 --- a/helpers/messages/getMessage.ts +++ b/helpers/messages/getMessage.ts @@ -6,7 +6,7 @@ export async function getMessage(bot: Bot, channelId: bigint, id: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.CHANNEL_MESSAGE(channelId, id), + bot.constants.routes.CHANNEL_MESSAGE(channelId, id), ); return bot.transformers.message(bot, result); diff --git a/helpers/messages/getMessages.ts b/helpers/messages/getMessages.ts index 8c5e8f9f0..828a9810f 100644 --- a/helpers/messages/getMessages.ts +++ b/helpers/messages/getMessages.ts @@ -11,20 +11,10 @@ export async function getMessages( throw new Error(bot.constants.Errors.INVALID_GET_MESSAGES_LIMIT); } - let url = bot.constants.endpoints.CHANNEL_MESSAGES(channelId); - - if (options) { - url += "?"; - if (isGetMessagesAfter(options) && options.after) url += `after=${options.after}`; - if (isGetMessagesBefore(options) && options.before) url += `&before=${options.before}`; - if (isGetMessagesAround(options) && options.around) url += `&around=${options.around}`; - if (isGetMessagesLimit(options) && options.limit) url += `&limit=${options.limit}`; - } - const result = await bot.rest.runMethod( bot.rest, "get", - url, + bot.constants.routes.CHANNEL_MESSAGES(channelId, options), ); return await Promise.all(result.map((res) => bot.transformers.message(bot, res))); diff --git a/helpers/messages/getReactions.ts b/helpers/messages/getReactions.ts index 564e7ad0a..5e6b0ad24 100644 --- a/helpers/messages/getReactions.ts +++ b/helpers/messages/getReactions.ts @@ -16,19 +16,10 @@ export async function getReactions( reaction = reaction.substring(3, reaction.length - 1); } - let url = bot.constants.endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, encodeURIComponent(reaction)); - - if (options) { - url += "?"; - - if (options.after) url += `after=${options.after}`; - if (options.limit) url += `&limit=${options.limit}`; - } - const users = await bot.rest.runMethod( bot.rest, "get", - url, + bot.constants.routes.CHANNEL_MESSAGE_REACTION(channelId, messageId, encodeURIComponent(reaction), options), ); return new Collection(users.map((u) => { diff --git a/helpers/messages/pinMessage.ts b/helpers/messages/pinMessage.ts index 8421c2ebd..14bb65d7d 100644 --- a/helpers/messages/pinMessage.ts +++ b/helpers/messages/pinMessage.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts"; /** Pin a message in a channel. Requires MANAGE_MESSAGES. Max pins allowed in a channel = 50. */ export async function pinMessage(bot: Bot, channelId: bigint, messageId: bigint) { - await bot.rest.runMethod(bot.rest, "put", bot.constants.endpoints.CHANNEL_PIN(channelId, messageId)); + await bot.rest.runMethod(bot.rest, "put", bot.constants.routes.CHANNEL_PIN(channelId, messageId)); } diff --git a/helpers/messages/publishMessage.ts b/helpers/messages/publishMessage.ts index 296a1f629..8b44ed44e 100644 --- a/helpers/messages/publishMessage.ts +++ b/helpers/messages/publishMessage.ts @@ -6,7 +6,7 @@ export async function publishMessage(bot: Bot, channelId: bigint, messageId: big const data = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId), + bot.constants.routes.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId), ); return bot.transformers.message(bot, data); diff --git a/helpers/messages/removeAllReactions.ts b/helpers/messages/removeAllReactions.ts index 11c6ae5f1..e65c76680 100644 --- a/helpers/messages/removeAllReactions.ts +++ b/helpers/messages/removeAllReactions.ts @@ -5,6 +5,6 @@ export async function removeAllReactions(bot: Bot, channelId: bigint, messageId: await bot.rest.runMethod( bot.rest, "delete", - bot.constants.endpoints.CHANNEL_MESSAGE_REACTIONS(channelId, messageId), + bot.constants.routes.CHANNEL_MESSAGE_REACTIONS(channelId, messageId), ); } diff --git a/helpers/messages/removeReaction.ts b/helpers/messages/removeReaction.ts index caa1f6b4c..ee9c8e895 100644 --- a/helpers/messages/removeReaction.ts +++ b/helpers/messages/removeReaction.ts @@ -18,12 +18,12 @@ export async function removeReaction( bot.rest, "delete", options?.userId - ? bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_USER( + ? bot.constants.routes.CHANNEL_MESSAGE_REACTION_USER( channelId, messageId, - encodeURIComponent(reaction), + reaction, options.userId, ) - : bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, encodeURIComponent(reaction)), + : bot.constants.routes.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction), ); } diff --git a/helpers/messages/removeReactionEmoji.ts b/helpers/messages/removeReactionEmoji.ts index 3176978fc..03f509028 100644 --- a/helpers/messages/removeReactionEmoji.ts +++ b/helpers/messages/removeReactionEmoji.ts @@ -11,6 +11,6 @@ export async function removeReactionEmoji(bot: Bot, channelId: bigint, messageId await bot.rest.runMethod( bot.rest, "delete", - bot.constants.endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction), + bot.constants.routes.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction), ); } diff --git a/helpers/messages/sendMessage.ts b/helpers/messages/sendMessage.ts index 040cfe5c8..26a973574 100644 --- a/helpers/messages/sendMessage.ts +++ b/helpers/messages/sendMessage.ts @@ -9,7 +9,7 @@ export async function sendMessage(bot: Bot, channelId: bigint, content: CreateMe const result = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.CHANNEL_MESSAGES(channelId), + bot.constants.routes.CHANNEL_MESSAGES(channelId), { content: content.content, tts: content.tts, diff --git a/helpers/messages/unpinMessage.ts b/helpers/messages/unpinMessage.ts index 8e9f628c7..bbc538f8f 100644 --- a/helpers/messages/unpinMessage.ts +++ b/helpers/messages/unpinMessage.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts"; export async function unpinMessage(bot: Bot, channelId: bigint, messageId: bigint) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.CHANNEL_PIN(channelId, messageId)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.CHANNEL_PIN(channelId, messageId)); } diff --git a/helpers/misc/editBotProfile.ts b/helpers/misc/editBotProfile.ts index 06b2a8892..f3b2bd5c3 100644 --- a/helpers/misc/editBotProfile.ts +++ b/helpers/misc/editBotProfile.ts @@ -7,7 +7,7 @@ import { DiscordUser } from "../../types/discord.ts"; export async function editBotProfile(bot: Bot, options: { username?: string; botAvatarURL?: string | null }) { const avatar = options?.botAvatarURL ? await bot.utils.urlToBase64(options?.botAvatarURL) : options?.botAvatarURL; - const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.USER_BOT(), { + const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.routes.USER_BOT(), { username: options.username?.trim(), avatar, }); diff --git a/helpers/misc/getGatewayBot.ts b/helpers/misc/getGatewayBot.ts index 67e80ca39..e51e647ec 100644 --- a/helpers/misc/getGatewayBot.ts +++ b/helpers/misc/getGatewayBot.ts @@ -3,7 +3,7 @@ import { DiscordGetGatewayBot } from "../../types/discord.ts"; /** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */ export async function getGatewayBot(bot: Bot) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GATEWAY_BOT()); + const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.routes.GATEWAY_BOT()); return bot.transformers.gatewayBot(result); } diff --git a/helpers/misc/getUser.ts b/helpers/misc/getUser.ts index f8fb79c35..dda9d36cd 100644 --- a/helpers/misc/getUser.ts +++ b/helpers/misc/getUser.ts @@ -3,7 +3,7 @@ import { DiscordUser } from "../../types/discord.ts"; /** This function will return the raw user payload in the rare cases you need to fetch a user directly from the API. */ export async function getUser(bot: Bot, userId: bigint) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.USER(userId)); + const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.routes.USER(userId)); return bot.transformers.user(bot, result); } diff --git a/helpers/misc/nitroStickerPacks.ts b/helpers/misc/nitroStickerPacks.ts index 2f26d418b..d682499fa 100644 --- a/helpers/misc/nitroStickerPacks.ts +++ b/helpers/misc/nitroStickerPacks.ts @@ -6,7 +6,7 @@ export async function nitroStickerPacks(bot: Bot) { const packs = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.NITRO_STICKER_PACKS(), + bot.constants.routes.NITRO_STICKER_PACKS(), ); return packs.map((pack) => bot.transformers.stickerPack(bot, pack)); diff --git a/helpers/oauth/getApplicationInfo.ts b/helpers/oauth/getApplicationInfo.ts index 47747f49f..fd7e78d76 100644 --- a/helpers/oauth/getApplicationInfo.ts +++ b/helpers/oauth/getApplicationInfo.ts @@ -6,7 +6,7 @@ export async function getApplicationInfo(bot: Bot) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.OAUTH2_APPLICATION(), + bot.constants.routes.OAUTH2_APPLICATION(), ); return bot.transformers.application(bot, result); diff --git a/helpers/roles/addRole.ts b/helpers/roles/addRole.ts index f893b9001..b0f751961 100644 --- a/helpers/roles/addRole.ts +++ b/helpers/roles/addRole.ts @@ -5,7 +5,7 @@ export async function addRole(bot: Bot, guildId: bigint, memberId: bigint, roleI await bot.rest.runMethod( bot.rest, "put", - bot.constants.endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId), + bot.constants.routes.GUILD_MEMBER_ROLE(guildId, memberId, roleId), { reason }, ); } diff --git a/helpers/roles/createRole.ts b/helpers/roles/createRole.ts index bbfa825e5..715599ab9 100644 --- a/helpers/roles/createRole.ts +++ b/helpers/roles/createRole.ts @@ -4,7 +4,7 @@ import { PermissionStrings } from "../../types/shared.ts"; /** Create a new role for the guild. Requires the MANAGE_ROLES permission. */ export async function createRole(bot: Bot, guildId: bigint, options: CreateGuildRole, reason?: string) { - const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.GUILD_ROLES(guildId), { + const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.routes.GUILD_ROLES(guildId), { name: options.name, color: options.color, hoist: options.hoist, diff --git a/helpers/roles/deleteRole.ts b/helpers/roles/deleteRole.ts index 7cb8cb24b..733353e15 100644 --- a/helpers/roles/deleteRole.ts +++ b/helpers/roles/deleteRole.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts"; /** Delete a guild role. Requires the MANAGE_ROLES permission. */ export async function deleteRole(bot: Bot, guildId: bigint, id: bigint) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.GUILD_ROLE(guildId, id)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.GUILD_ROLE(guildId, id)); } diff --git a/helpers/roles/editRole.ts b/helpers/roles/editRole.ts index e0dc84f45..948e8aeb1 100644 --- a/helpers/roles/editRole.ts +++ b/helpers/roles/editRole.ts @@ -7,7 +7,7 @@ export async function editRole(bot: Bot, guildId: bigint, id: bigint, options: E const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.GUILD_ROLE(guildId, id), + bot.constants.routes.GUILD_ROLE(guildId, id), { name: options.name, color: options.color, diff --git a/helpers/roles/getRoles.ts b/helpers/roles/getRoles.ts index 2b71cb8dd..a40fc93ee 100644 --- a/helpers/roles/getRoles.ts +++ b/helpers/roles/getRoles.ts @@ -7,7 +7,7 @@ import { DiscordRole } from "../../types/discord.ts"; * ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your roles will be cached in your guild.** */ export async function getRoles(bot: Bot, guildId: bigint) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_ROLES(guildId)); + const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.routes.GUILD_ROLES(guildId)); const roleStructures = result.map((role) => bot.transformers.role(bot, { role, guildId })); diff --git a/helpers/roles/modifyRolePositions.ts b/helpers/roles/modifyRolePositions.ts index cc02e7bf6..11394542e 100644 --- a/helpers/roles/modifyRolePositions.ts +++ b/helpers/roles/modifyRolePositions.ts @@ -7,7 +7,7 @@ export async function modifyRolePositions(bot: Bot, guildId: bigint, options: Mo const roles = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.GUILD_ROLES(guildId), + bot.constants.routes.GUILD_ROLES(guildId), options, ); diff --git a/helpers/roles/removeRole.ts b/helpers/roles/removeRole.ts index fdf8bc9e8..7e2cf2e83 100644 --- a/helpers/roles/removeRole.ts +++ b/helpers/roles/removeRole.ts @@ -5,7 +5,7 @@ export async function removeRole(bot: Bot, guildId: bigint, memberId: bigint, ro await bot.rest.runMethod( bot.rest, "delete", - bot.constants.endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId), + bot.constants.routes.GUILD_MEMBER_ROLE(guildId, memberId, roleId), { reason }, ); } diff --git a/helpers/templates/createGuildFromTemplate.ts b/helpers/templates/createGuildFromTemplate.ts index a3263637d..e6b569305 100644 --- a/helpers/templates/createGuildFromTemplate.ts +++ b/helpers/templates/createGuildFromTemplate.ts @@ -13,7 +13,7 @@ export async function createGuildFromTemplate(bot: Bot, templateCode: string, da const createdGuild = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.GUILD_TEMPLATE(templateCode), + bot.constants.routes.TEMPLATE(templateCode), data, ); diff --git a/helpers/templates/createGuildTemplate.ts b/helpers/templates/createGuildTemplate.ts index dbc8770a0..ad0f5ae0a 100644 --- a/helpers/templates/createGuildTemplate.ts +++ b/helpers/templates/createGuildTemplate.ts @@ -14,7 +14,7 @@ export async function createGuildTemplate(bot: Bot, guildId: bigint, data: Creat return await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.GUILD_TEMPLATES(guildId), + bot.constants.routes.GUILD_TEMPLATES(guildId), data, ); } diff --git a/helpers/templates/deleteGuildTemplate.ts b/helpers/templates/deleteGuildTemplate.ts index 7841dd355..51d263ede 100644 --- a/helpers/templates/deleteGuildTemplate.ts +++ b/helpers/templates/deleteGuildTemplate.ts @@ -9,6 +9,6 @@ export async function deleteGuildTemplate(bot: Bot, guildId: bigint, templateCod await bot.rest.runMethod( bot.rest, "delete", - `${bot.constants.endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, + bot.constants.routes.GUILD_TEMPLATE(guildId, templateCode), ); } diff --git a/helpers/templates/editGuildTemplate.ts b/helpers/templates/editGuildTemplate.ts index 5461b4de3..f68fac58a 100644 --- a/helpers/templates/editGuildTemplate.ts +++ b/helpers/templates/editGuildTemplate.ts @@ -17,7 +17,7 @@ export async function editGuildTemplate(bot: Bot, guildId: bigint, templateCode: return await bot.rest.runMethod( bot.rest, "patch", - `${bot.constants.endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, + bot.constants.routes.GUILD_TEMPLATE(guildId, templateCode), { name: data.name, description: data.description, diff --git a/helpers/templates/getGuildTemplates.ts b/helpers/templates/getGuildTemplates.ts index da086f687..6f62069fa 100644 --- a/helpers/templates/getGuildTemplates.ts +++ b/helpers/templates/getGuildTemplates.ts @@ -7,7 +7,7 @@ export async function getGuildTemplates(bot: Bot, guildId: bigint) { const templates = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_TEMPLATES(guildId), + bot.constants.routes.GUILD_TEMPLATES(guildId), ); return new Collection(templates.map((template) => [template.code, bot.transformers.template(bot, template)])); diff --git a/helpers/templates/getTemplate.ts b/helpers/templates/getTemplate.ts index 1389fbb67..9905fa709 100644 --- a/helpers/templates/getTemplate.ts +++ b/helpers/templates/getTemplate.ts @@ -6,7 +6,7 @@ export async function getTemplate(bot: Bot, templateCode: string) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_TEMPLATE(templateCode), + bot.constants.routes.TEMPLATE(templateCode), ); return bot.transformers.template(bot, result); diff --git a/helpers/templates/syncGuildTemplate.ts b/helpers/templates/syncGuildTemplate.ts index ad212195c..2e607a602 100644 --- a/helpers/templates/syncGuildTemplate.ts +++ b/helpers/templates/syncGuildTemplate.ts @@ -9,6 +9,6 @@ export async function syncGuildTemplate(bot: Bot, guildId: bigint, templateCode: return await bot.rest.runMethod( bot.rest, "put", - `${bot.constants.endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, + bot.constants.routes.GUILD_TEMPLATE(guildId, templateCode), ); } diff --git a/helpers/webhooks/createWebhook.ts b/helpers/webhooks/createWebhook.ts index 650ba85a5..b1d153a62 100644 --- a/helpers/webhooks/createWebhook.ts +++ b/helpers/webhooks/createWebhook.ts @@ -10,7 +10,7 @@ export async function createWebhook(bot: Bot, channelId: bigint, options: Create const result = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId), + bot.constants.routes.CHANNEL_WEBHOOKS(channelId), { name: options.name, avatar: options.avatar ? await bot.utils.urlToBase64(options.avatar) : undefined, diff --git a/helpers/webhooks/deleteWebhook.ts b/helpers/webhooks/deleteWebhook.ts index d70498fa4..6537b75dd 100644 --- a/helpers/webhooks/deleteWebhook.ts +++ b/helpers/webhooks/deleteWebhook.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts"; /** Delete a webhook permanently. Requires the `MANAGE_WEBHOOKS` permission. Returns a undefined on success */ export async function deleteWebhook(bot: Bot, webhookId: bigint, reason?: string) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.WEBHOOK_ID(webhookId), { reason }); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.WEBHOOK_ID(webhookId), { reason }); } diff --git a/helpers/webhooks/deleteWebhookMessage.ts b/helpers/webhooks/deleteWebhookMessage.ts index f7e834e36..0b17e2222 100644 --- a/helpers/webhooks/deleteWebhookMessage.ts +++ b/helpers/webhooks/deleteWebhookMessage.ts @@ -12,11 +12,9 @@ export async function deleteWebhookMessage( messageId: bigint, options?: DeleteWebhookMessageOptions, ) { - let url = bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId); - - // QUERY PARAMS - if (options?.threadId) { - url += `?threadId=${options.threadId}`; - } - await bot.rest.runMethod(bot.rest, "delete", url); + await bot.rest.runMethod( + bot.rest, + "delete", + bot.constants.routes.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId, options), + ); } diff --git a/helpers/webhooks/deleteWebhookWithToken.ts b/helpers/webhooks/deleteWebhookWithToken.ts index 0591a212c..619aadc98 100644 --- a/helpers/webhooks/deleteWebhookWithToken.ts +++ b/helpers/webhooks/deleteWebhookWithToken.ts @@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts"; /** Delete a webhook permanently. Returns a undefined on success */ export async function deleteWebhookWithToken(bot: Bot, webhookId: bigint, webhookToken: string) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.WEBHOOK(webhookId, webhookToken)); + await bot.rest.runMethod(bot.rest, "delete", bot.constants.routes.WEBHOOK(webhookId, webhookToken)); } diff --git a/helpers/webhooks/editWebhook.ts b/helpers/webhooks/editWebhook.ts index 069795d95..5292792f6 100644 --- a/helpers/webhooks/editWebhook.ts +++ b/helpers/webhooks/editWebhook.ts @@ -6,7 +6,7 @@ export async function editWebhook(bot: Bot, webhookId: bigint, options: ModifyWe const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.WEBHOOK_ID(webhookId), + bot.constants.routes.WEBHOOK_ID(webhookId), { name: options.name, avatar: options.avatar, diff --git a/helpers/webhooks/editWebhookMessage.ts b/helpers/webhooks/editWebhookMessage.ts index 98d5a15e4..b7898c83a 100644 --- a/helpers/webhooks/editWebhookMessage.ts +++ b/helpers/webhooks/editWebhookMessage.ts @@ -11,95 +11,93 @@ export async function editWebhookMessage( webhookToken: string, options: EditWebhookMessage & { messageId?: bigint; threadId?: bigint }, ) { - let url = options.messageId - ? bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, options.messageId) - : bot.constants.endpoints.WEBHOOK_MESSAGE_ORIGINAL(webhookId, webhookToken); + const result = await bot.rest.runMethod( + bot.rest, + "patch", + options.messageId + ? bot.constants.routes.WEBHOOK_MESSAGE(webhookId, webhookToken, options.messageId, options) + : bot.constants.routes.WEBHOOK_MESSAGE_ORIGINAL(webhookId, webhookToken, options), + { + content: options.content, + embeds: options.embeds?.map((embed) => bot.transformers.reverse.embed(bot, embed)), + file: options.file, + allowed_mentions: options.allowedMentions + ? { + parse: options.allowedMentions.parse, + roles: options.allowedMentions.roles?.map((id) => id.toString()), + users: options.allowedMentions.users?.map((id) => id.toString()), + replied_user: options.allowedMentions.repliedUser, + } + : undefined, + attachments: options.attachments?.map((attachment) => ({ + id: attachment.id.toString(), + filename: attachment.filename, + content_type: attachment.contentType, + size: attachment.size, + url: attachment.url, + proxy_url: attachment.proxyUrl, + height: attachment.height, + width: attachment.width, + ephemeral: attachment.ephemeral, + })), + components: options.components?.map((component) => ({ + type: component.type, + components: component.components.map((subComponent) => { + if (subComponent.type === MessageComponentTypes.InputText) { + return { + type: subComponent.type, + style: subComponent.style, + custom_id: subComponent.customId, + label: subComponent.label, + placeholder: subComponent.placeholder, + min_length: subComponent.minLength ?? subComponent.required === false ? 0 : subComponent.minLength, + max_length: subComponent.maxLength, + }; + } - // QUERY PARAMS - if (options.threadId) { - url += `?thread_id=${options.threadId}`; - } + if (subComponent.type === MessageComponentTypes.SelectMenu) { + return { + type: subComponent.type, + custom_id: subComponent.customId, + placeholder: subComponent.placeholder, + min_values: subComponent.minValues, + max_values: subComponent.maxValues, + options: subComponent.options.map((option) => ({ + label: option.label, + value: option.value, + description: option.description, + emoji: option.emoji + ? { + id: option.emoji.id?.toString(), + name: option.emoji.name, + animated: option.emoji.animated, + } + : undefined, + default: option.default, + })), + }; + } - const result = await bot.rest.runMethod(bot.rest, "patch", url, { - content: options.content, - embeds: options.embeds?.map((embed) => bot.transformers.reverse.embed(bot, embed)), - file: options.file, - allowed_mentions: options.allowedMentions - ? { - parse: options.allowedMentions.parse, - roles: options.allowedMentions.roles?.map((id) => id.toString()), - users: options.allowedMentions.users?.map((id) => id.toString()), - replied_user: options.allowedMentions.repliedUser, - } - : undefined, - attachments: options.attachments?.map((attachment) => ({ - id: attachment.id.toString(), - filename: attachment.filename, - content_type: attachment.contentType, - size: attachment.size, - url: attachment.url, - proxy_url: attachment.proxyUrl, - height: attachment.height, - width: attachment.width, - ephemeral: attachment.ephemeral, - })), - components: options.components?.map((component) => ({ - type: component.type, - components: component.components.map((subComponent) => { - if (subComponent.type === MessageComponentTypes.InputText) { return { type: subComponent.type, - style: subComponent.style, custom_id: subComponent.customId, label: subComponent.label, - placeholder: subComponent.placeholder, - min_length: subComponent.minLength ?? subComponent.required === false ? 0 : subComponent.minLength, - max_length: subComponent.maxLength, + style: subComponent.style, + emoji: "emoji" in subComponent && subComponent.emoji + ? { + id: subComponent.emoji.id?.toString(), + name: subComponent.emoji.name, + animated: subComponent.emoji.animated, + } + : undefined, + url: "url" in subComponent ? subComponent.url : undefined, + disabled: "disabled" in subComponent ? subComponent.disabled : undefined, }; - } - - if (subComponent.type === MessageComponentTypes.SelectMenu) { - return { - type: subComponent.type, - custom_id: subComponent.customId, - placeholder: subComponent.placeholder, - min_values: subComponent.minValues, - max_values: subComponent.maxValues, - options: subComponent.options.map((option) => ({ - label: option.label, - value: option.value, - description: option.description, - emoji: option.emoji - ? { - id: option.emoji.id?.toString(), - name: option.emoji.name, - animated: option.emoji.animated, - } - : undefined, - default: option.default, - })), - }; - } - - return { - type: subComponent.type, - custom_id: subComponent.customId, - label: subComponent.label, - style: subComponent.style, - emoji: "emoji" in subComponent && subComponent.emoji - ? { - id: subComponent.emoji.id?.toString(), - name: subComponent.emoji.name, - animated: subComponent.emoji.animated, - } - : undefined, - url: "url" in subComponent ? subComponent.url : undefined, - disabled: "disabled" in subComponent ? subComponent.disabled : undefined, - }; - }), - })), - message_id: options.messageId?.toString(), - }); + }), + })), + message_id: options.messageId?.toString(), + }, + ); return bot.transformers.message(bot, result); } diff --git a/helpers/webhooks/editWebhookWithToken.ts b/helpers/webhooks/editWebhookWithToken.ts index a5d75ccef..abebc0d94 100644 --- a/helpers/webhooks/editWebhookWithToken.ts +++ b/helpers/webhooks/editWebhookWithToken.ts @@ -12,7 +12,7 @@ export async function editWebhookWithToken( const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.WEBHOOK(webhookId, webhookToken), + bot.constants.routes.WEBHOOK(webhookId, webhookToken), { name: options.name, avatar: options.avatar, diff --git a/helpers/webhooks/getWebhook.ts b/helpers/webhooks/getWebhook.ts index 23bda7af0..cb7a644fa 100644 --- a/helpers/webhooks/getWebhook.ts +++ b/helpers/webhooks/getWebhook.ts @@ -6,7 +6,7 @@ export async function getWebhook(bot: Bot, webhookId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.WEBHOOK_ID(webhookId), + bot.constants.routes.WEBHOOK_ID(webhookId), ); return bot.transformers.webhook(bot, result); diff --git a/helpers/webhooks/getWebhookMessage.ts b/helpers/webhooks/getWebhookMessage.ts index 12fb16361..f8b952db1 100644 --- a/helpers/webhooks/getWebhookMessage.ts +++ b/helpers/webhooks/getWebhookMessage.ts @@ -13,14 +13,11 @@ export async function getWebhookMessage( messageId: bigint, options?: GetWebhookMessageOptions, ) { - let url = bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId); - - // QUERY PARAMS - if (options?.threadId) { - url += `?thread_id=${options.threadId}`; - } - - const result = await bot.rest.runMethod(bot.rest, "get", url); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.routes.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId, options), + ); return bot.transformers.message(bot, result); } diff --git a/helpers/webhooks/getWebhookWithToken.ts b/helpers/webhooks/getWebhookWithToken.ts index a7ec3260a..92f7b2f68 100644 --- a/helpers/webhooks/getWebhookWithToken.ts +++ b/helpers/webhooks/getWebhookWithToken.ts @@ -6,7 +6,7 @@ export async function getWebhookWithToken(bot: Bot, webhookId: bigint, token: st const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.WEBHOOK(webhookId, token), + bot.constants.routes.WEBHOOK(webhookId, token), ); return bot.transformers.webhook(bot, result); diff --git a/helpers/webhooks/getWebhooks.ts b/helpers/webhooks/getWebhooks.ts index 0b35ed312..2487a2d21 100644 --- a/helpers/webhooks/getWebhooks.ts +++ b/helpers/webhooks/getWebhooks.ts @@ -7,7 +7,7 @@ export async function getWebhooks(bot: Bot, guildId: bigint) { const result = await bot.rest.runMethod( bot.rest, "get", - bot.constants.endpoints.GUILD_WEBHOOKS(guildId), + bot.constants.routes.GUILD_WEBHOOKS(guildId), ); return new Collection(result.map((hook) => { diff --git a/helpers/webhooks/sendWebhook.ts b/helpers/webhooks/sendWebhook.ts index 920c8faf8..a97febb91 100644 --- a/helpers/webhooks/sendWebhook.ts +++ b/helpers/webhooks/sendWebhook.ts @@ -17,9 +17,7 @@ export async function sendWebhook(bot: Bot, webhookId: bigint, webhookToken: str const result = await bot.rest.runMethod( bot.rest, "post", - `${bot.constants.endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${options.wait ?? false}${ - options.threadId ? `&thread_id=${options.threadId}` : "" - }`, + bot.constants.routes.WEBHOOK(webhookId, webhookToken, options), { wait: options.wait, thread_id: options.threadId, diff --git a/plugins/helpers/src/getMembersPaginated.ts b/plugins/helpers/src/getMembersPaginated.ts index 1a1bfc7af..8449859b6 100644 --- a/plugins/helpers/src/getMembersPaginated.ts +++ b/plugins/helpers/src/getMembersPaginated.ts @@ -33,9 +33,10 @@ export async function getMembersPaginated( const result = await bot.rest.runMethod( bot.rest, "get", - `${bot.constants.endpoints.GUILD_MEMBERS(guildId)}?limit=${membersLeft > 1000 ? 1000 : membersLeft}${ - options?.after ? `&after=${options.after}` : "" - }`, + bot.constants.routes.GUILD_MEMBERS(guildId, { + limit: membersLeft > 1000 ? 1000 : membersLeft, + after: options.after, + }), ); const discordenoMembers = result.map((member) => diff --git a/plugins/helpers/src/suppressEmbeds.ts b/plugins/helpers/src/suppressEmbeds.ts index 972b9e8bd..cac616909 100644 --- a/plugins/helpers/src/suppressEmbeds.ts +++ b/plugins/helpers/src/suppressEmbeds.ts @@ -9,7 +9,7 @@ export async function suppressEmbeds( const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.CHANNEL_MESSAGE(channelId, messageId), + bot.constants.routes.CHANNEL_MESSAGE(channelId, messageId), { flags: 4 }, ); diff --git a/plugins/helpers/src/threads.ts b/plugins/helpers/src/threads.ts index 602caa250..fc83a7d17 100644 --- a/plugins/helpers/src/threads.ts +++ b/plugins/helpers/src/threads.ts @@ -25,7 +25,7 @@ export async function editThread(bot: Bot, threadId: bigint, options: ModifyThre const result = await bot.rest.runMethod( bot.rest, "patch", - bot.constants.endpoints.CHANNEL_BASE(threadId), + bot.constants.routes.CHANNEL(threadId), { name: options.name, archived: options.archived, diff --git a/rest/runMethod.ts b/rest/runMethod.ts index c5cab72fd..e48bca869 100644 --- a/rest/runMethod.ts +++ b/rest/runMethod.ts @@ -1,11 +1,11 @@ import { RestManager } from "../bot.ts"; -import { API_VERSION, BASE_URL, IMAGE_BASE_URL } from "../util/constants.ts"; +import { API_VERSION, BASE_URL, baseEndpoints, IMAGE_BASE_URL } from "../util/constants.ts"; import { RestRequestRejection, RestRequestResponse } from "./rest.ts"; export async function runMethod( rest: RestManager, method: "get" | "post" | "put" | "delete" | "patch", - url: string, + route: string, body?: unknown, options?: { retryCount?: number; @@ -14,7 +14,7 @@ export async function runMethod( }, ): Promise { rest.debug( - `[REST - RequestCreate] Method: ${method} | URL: ${url} | Retry Count: ${ + `[REST - RequestCreate] Method: ${method} | URL: ${route} | Retry Count: ${ options?.retryCount ?? 0 } | Bucket ID: ${options?.bucketId} | Body: ${ JSON.stringify( @@ -28,8 +28,8 @@ export async function runMethod( Error.captureStackTrace(errorStack); // For proxies we don't need to do any of the legwork so we just forward the request - if (!url.startsWith(`${BASE_URL}/v${API_VERSION}`) && !url.startsWith(IMAGE_BASE_URL)) { - const result = await fetch(url, { + if (!baseEndpoints.BASE_URL.startsWith(BASE_URL) && route[0] === "/") { + const result = await fetch(`${baseEndpoints.BASE_URL}${route}`, { body: body ? JSON.stringify(body) : undefined, headers: { Authorization: rest.secretKey, @@ -56,7 +56,7 @@ export async function runMethod( rest.processRequest( rest, { - url, + url: route[0] === "/" ? `${BASE_URL}/v${API_VERSION}${route}` : route, method, reject: (data: RestRequestRejection) => { const restError = rest.convertRestError(errorStack, data); diff --git a/util/constants.ts b/util/constants.ts index 9c4f2c96e..a195a4f73 100644 --- a/util/constants.ts +++ b/util/constants.ts @@ -1,3 +1,19 @@ +import { ListArchivedThreads } from "../helpers/channels/threads/getArchivedThreads.ts"; +import { GetGuildAuditLog } from "../helpers/guilds/getAuditLogs.ts"; +import { GetBans } from "../helpers/guilds/getBans.ts"; +import { GetGuildPruneCountQuery } from "../helpers/guilds/getPruneCount.ts"; +import { GetScheduledEventUsers } from "../helpers/guilds/scheduledEvents/getScheduledEventUsers.ts"; +import { GetInvite } from "../helpers/invites/getInvite.ts"; +import { ListGuildMembers } from "../helpers/members/getMembers.ts"; +import { + GetMessagesOptions, + isGetMessagesAfter, + isGetMessagesAround, + isGetMessagesBefore, + isGetMessagesLimit, +} from "../helpers/messages/getMessages.ts"; +import { GetReactions } from "../helpers/messages/getReactions.ts"; + /** https://discord.com/developers/docs/reference#api-reference-base-url */ export const BASE_URL = "https://discord.com/api"; @@ -23,158 +39,488 @@ export const baseEndpoints = { CDN_URL: IMAGE_BASE_URL, }; -const GUILDS_BASE = (guildId: bigint) => `${baseEndpoints.BASE_URL}/guilds/${guildId}`; -const CHANNEL_BASE = (channelId: bigint) => `${baseEndpoints.BASE_URL}/channels/${channelId}`; - -export const endpoints = { - GUILDS_BASE, - CHANNEL_BASE, - - GATEWAY_BOT: () => `${baseEndpoints.BASE_URL}/gateway/bot`, +export const routes = { + GATEWAY_BOT: () => { + return `/gateway/bot`; + }, // Channel Endpoints - CHANNEL_MESSAGE: (channelId: bigint, messageId: bigint) => `${CHANNEL_BASE(channelId)}/messages/${messageId}`, - CHANNEL_MESSAGES: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/messages`, - CHANNEL_PIN: (channelId: bigint, messageId: bigint) => `${CHANNEL_BASE(channelId)}/pins/${messageId}`, - CHANNEL_PINS: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/pins`, - CHANNEL_BULK_DELETE: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/messages/bulk-delete`, - CHANNEL_INVITES: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/invites`, - CHANNEL_WEBHOOKS: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/webhooks`, - CHANNEL_MESSAGE_REACTION_ME: (channelId: bigint, messageId: bigint, emoji: string) => - `${CHANNEL_BASE(channelId)}/messages/${messageId}/reactions/${emoji}/@me`, - CHANNEL_MESSAGE_REACTION_USER: (channelId: bigint, messageId: bigint, emoji: string, userId: bigint) => - `${CHANNEL_BASE(channelId)}/messages/${messageId}/reactions/${emoji}/${userId}`, - CHANNEL_MESSAGE_REACTIONS: (channelId: bigint, messageId: bigint) => - `${CHANNEL_BASE(channelId)}/messages/${messageId}/reactions`, - CHANNEL_MESSAGE_REACTION: (channelId: bigint, messageId: bigint, emoji: string) => - `${CHANNEL_BASE(channelId)}/messages/${messageId}/reactions/${emoji}`, - CHANNEL_FOLLOW: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/followers`, - CHANNEL_MESSAGE_CROSSPOST: (channelId: bigint, messageId: bigint) => - `${CHANNEL_BASE(channelId)}/messages/${messageId}/crosspost`, - CHANNEL_OVERWRITE: (channelId: bigint, overwriteId: bigint) => - `${CHANNEL_BASE(channelId)}/permissions/${overwriteId}`, + CHANNEL: (channelId: bigint) => { + return `/channels/${channelId}`; + }, + CHANNEL_MESSAGE: (channelId: bigint, messageId: bigint) => { + return `/channels/${channelId}/messages/${messageId}`; + }, + CHANNEL_MESSAGES: (channelId: bigint, options?: GetMessagesOptions) => { + let url = `/channels/${channelId}/messages?`; + + if (options) { + if (isGetMessagesAfter(options) && options.after) url += `after=${options.after}`; + if (isGetMessagesBefore(options) && options.before) url += `&before=${options.before}`; + if (isGetMessagesAround(options) && options.around) url += `&around=${options.around}`; + if (isGetMessagesLimit(options) && options.limit) url += `&limit=${options.limit}`; + } + + return url; + }, + CHANNEL_PIN: (channelId: bigint, messageId: bigint) => { + return `/channels/${channelId}/pins/${messageId}`; + }, + CHANNEL_PINS: (channelId: bigint) => { + return `/channels/${channelId}/pins`; + }, + CHANNEL_BULK_DELETE: (channelId: bigint) => { + return `/channels/${channelId}/messages/bulk-delete`; + }, + CHANNEL_INVITES: (channelId: bigint) => { + return `/channels/${channelId}/invites`; + }, + CHANNEL_WEBHOOKS: (channelId: bigint) => { + return `/channels/${channelId}/webhooks`; + }, + CHANNEL_MESSAGE_REACTION_ME: (channelId: bigint, messageId: bigint, emoji: string) => { + return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`; + }, + CHANNEL_MESSAGE_REACTION_USER: (channelId: bigint, messageId: bigint, emoji: string, userId: bigint) => { + return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/${userId}`; + }, + CHANNEL_MESSAGE_REACTIONS: (channelId: bigint, messageId: bigint) => { + return `/channels/${channelId}/messages/${messageId}/reactions`; + }, + CHANNEL_MESSAGE_REACTION: (channelId: bigint, messageId: bigint, emoji: string, options?: GetReactions) => { + let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`; + + if (options) { + if (options.after) url += `after=${options.after}`; + if (options.limit) url += `&limit=${options.limit}`; + } + + return url; + }, + CHANNEL_FOLLOW: (channelId: bigint) => { + return `/channels/${channelId}/followers`; + }, + CHANNEL_MESSAGE_CROSSPOST: (channelId: bigint, messageId: bigint) => { + return `/channels/${channelId}/messages/${messageId}/crosspost`; + }, + CHANNEL_OVERWRITE: (channelId: bigint, overwriteId: bigint) => { + return `/channels/${channelId}/permissions/${overwriteId}`; + }, // Bots SHALL NOT use this endpoint but they can - CHANNEL_TYPING: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/typing`, + CHANNEL_TYPING: (channelId: bigint) => { + return `/channels/${channelId}/typing`; + }, // Thread Endpoints - THREAD_START_PUBLIC: (channelId: bigint, messageId: bigint) => - `${endpoints.CHANNEL_MESSAGE(channelId, messageId)}/threads`, - THREAD_START_PRIVATE: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/threads`, - THREAD_ACTIVE: (guildId: bigint) => `${GUILDS_BASE(guildId)}/threads/active`, - THREAD_MEMBERS: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/thread-members`, - THREAD_ME: (channelId: bigint) => `${endpoints.THREAD_MEMBERS(channelId)}/@me`, - THREAD_USER: (channelId: bigint, userId: bigint) => `${endpoints.THREAD_MEMBERS(channelId)}/${userId}`, - THREAD_ARCHIVED_BASE: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/threads/archived`, - THREAD_ARCHIVED_PUBLIC: (channelId: bigint) => `${endpoints.THREAD_ARCHIVED_BASE(channelId)}/public`, - THREAD_ARCHIVED_PRIVATE: (channelId: bigint) => `${endpoints.THREAD_ARCHIVED_BASE(channelId)}/private`, - THREAD_ARCHIVED_PRIVATE_JOINED: (channelId: bigint) => - `${CHANNEL_BASE(channelId)}/users/@me/threads/archived/private`, + THREAD_START_PUBLIC: (channelId: bigint, messageId: bigint) => { + return `/channels/${channelId}/messages/${messageId}/threads`; + }, + THREAD_START_PRIVATE: (channelId: bigint) => { + return `/channels/${channelId}/threads`; + }, + THREAD_ACTIVE: (guildId: bigint) => { + return `/guilds/${guildId}/threads/active`; + }, + THREAD_MEMBERS: (channelId: bigint) => { + return `/channels/${channelId}/thread-members`; + }, + THREAD_ME: (channelId: bigint) => { + return `/channels/${channelId}/thread-members/@me`; + }, + THREAD_USER: (channelId: bigint, userId: bigint) => { + return `/channels/${channelId}/thread-members/${userId}`; + }, + THREAD_ARCHIVED: (channelId: bigint) => { + return `/channels/${channelId}/threads/archived`; + }, + THREAD_ARCHIVED_PUBLIC: (channelId: bigint, options?: ListArchivedThreads) => { + let url = `/channels/${channelId}/threads/archived/public?`; + + if (options) { + if (options.before) url += `before=${new Date(options.before).toISOString()}`; + if (options.limit) url += `&limit=${options.limit}`; + } + + return url; + }, + THREAD_ARCHIVED_PRIVATE: (channelId: bigint, options?: ListArchivedThreads) => { + let url = `/channels/${channelId}/threads/archived/private?`; + + if (options) { + if (options.before) url += `before=${new Date(options.before).toISOString()}`; + if (options.limit) url += `&limit=${options.limit}`; + } + + return url; + }, + THREAD_ARCHIVED_PRIVATE_JOINED: (channelId: bigint, options?: ListArchivedThreads) => { + let url = `/channels/${channelId}/users/@me/threads/archived/private?`; + + if (options) { + if (options.before) url += `before=${new Date(options.before).toISOString()}`; + if (options.limit) url += `&limit=${options.limit}`; + } + + return url; + }, // Thread -> Forum Endpoints - FORUM_START: (channelId: bigint) => `${CHANNEL_BASE(channelId)}/threads?has_message=true`, + FORUM_START: (channelId: bigint) => { + return `/channels/${channelId}/threads?has_message=true`; + }, // Guild Endpoints - GUILDS: () => `${baseEndpoints.BASE_URL}/guilds`, - GUILD_AUDIT_LOGS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/audit-logs`, - GUILD_BAN: (guildId: bigint, userId: bigint) => `${GUILDS_BASE(guildId)}/bans/${userId}`, - GUILD_BANS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/bans`, - GUILD_BANNER: (guildId: bigint, icon: string) => `${baseEndpoints.CDN_URL}/banners/${guildId}/${icon}`, - GUILD_CHANNELS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/channels`, - GUILD_WIDGET: (guildId: bigint) => `${GUILDS_BASE(guildId)}/widget`, - GUILD_EMOJI: (guildId: bigint, emojiId: bigint) => `${GUILDS_BASE(guildId)}/emojis/${emojiId}`, - GUILD_EMOJIS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/emojis`, - GUILD_ICON: (guildId: bigint, icon: string) => `${baseEndpoints.CDN_URL}/icons/${guildId}/${icon}`, - GUILD_INTEGRATION: (guildId: bigint, integrationId: bigint) => - `${GUILDS_BASE(guildId)}/integrations/${integrationId}`, - GUILD_INTEGRATION_SYNC: (guildId: bigint, integrationId: bigint) => - `${GUILDS_BASE(guildId)}/integrations/${integrationId}/sync`, - GUILD_INTEGRATIONS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/integrations?include_applications=true`, - GUILD_INVITES: (guildId: bigint) => `${GUILDS_BASE(guildId)}/invites`, - GUILD_LEAVE: (guildId: bigint) => `${baseEndpoints.BASE_URL}/users/@me/guilds/${guildId}`, - GUILD_MEMBER: (guildId: bigint, userId: bigint) => `${GUILDS_BASE(guildId)}/members/${userId}`, - GUILD_MEMBERS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/members`, - GUILD_MEMBER_ROLE: (guildId: bigint, memberId: bigint, roleId: bigint) => - `${GUILDS_BASE(guildId)}/members/${memberId}/roles/${roleId}`, - GUILD_MEMBERS_SEARCH: (guildId: bigint) => `${GUILDS_BASE(guildId)}/members/search`, - GUILD_PRUNE: (guildId: bigint) => `${GUILDS_BASE(guildId)}/prune`, - GUILD_REGIONS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/regions`, - GUILD_ROLE: (guildId: bigint, roleId: bigint) => `${GUILDS_BASE(guildId)}/roles/${roleId}`, - GUILD_ROLES: (guildId: bigint) => `${GUILDS_BASE(guildId)}/roles`, - GUILD_SPLASH: (guildId: bigint, icon: string) => `${baseEndpoints.CDN_URL}/splashes/${guildId}/${icon}`, - GUILD_VANITY_URL: (guildId: bigint) => `${GUILDS_BASE(guildId)}/vanity-url`, - GUILD_WEBHOOKS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/webhooks`, - GUILD_TEMPLATE: (code: string) => `${baseEndpoints.BASE_URL}/guilds/templates/${code}`, - GUILD_TEMPLATES: (guildId: bigint) => `${GUILDS_BASE(guildId)}/templates`, - GUILD_PREVIEW: (guildId: bigint) => `${GUILDS_BASE(guildId)}/preview`, - UPDATE_VOICE_STATE: (guildId: bigint, userId?: bigint) => `${GUILDS_BASE(guildId)}/voice-states/${userId ?? "@me"}`, - GUILD_WELCOME_SCREEN: (guildId: bigint) => `${GUILDS_BASE(guildId)}/welcome-screen`, - GUILD_SCHEDULED_EVENTS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/scheduled-events`, - GUILD_SCHEDULED_EVENT: (guildId: bigint, eventId: bigint) => `${GUILDS_BASE(guildId)}/scheduled-events/${eventId}`, - GUILD_SCHEDULED_EVENT_USERS: (guildId: bigint, eventId: bigint) => - `${GUILDS_BASE(guildId)}/scheduled-events/${eventId}/users`, + GUILD: (guildId: bigint, withCounts?: boolean) => { + let url = `/guilds/${guildId}?`; + if (withCounts !== undefined) { + url += `with_counts=${withCounts}`; + } + + return url; + }, + GUILDS: () => { + return `/guilds`; + }, + GUILD_AUDIT_LOGS: (guildId: bigint, options?: GetGuildAuditLog) => { + let url = `/guilds/${guildId}/audit-logs?`; + + if (options) { + if (options.actionType) url += `action_type=${options.actionType}`; + if (options.before) url += `&before=${options.before}`; + if (options.limit) url += `&limit=${options.limit}`; + if (options.userId) url += `&user_id=${options.userId}`; + } + + return url; + }, + GUILD_BAN: (guildId: bigint, userId: bigint) => { + return `/guilds/${guildId}/bans/${userId}`; + }, + GUILD_BANS: (guildId: bigint, options?: GetBans) => { + let url = `/guilds/${guildId}/bans?`; + + if (options) { + if (options.limit) url += `limit=${options.limit}`; + if (options.after) url += `&after=${options.after}`; + if (options.before) url += `&before=${options.before}`; + } + + return url; + }, + // TODO: move this away + GUILD_BANNER: (guildId: bigint, icon: string) => { + return `${baseEndpoints.CDN_URL}/banners/${guildId}/${icon}`; + }, + GUILD_CHANNELS: (guildId: bigint) => { + return `/guilds/${guildId}/channels`; + }, + GUILD_WIDGET: (guildId: bigint) => { + return `/guilds/${guildId}/widget`; + }, + GUILD_WIDGET_JSON: (guildId: bigint) => { + return `/guilds/${guildId}/widget.json`; + }, + GUILD_WIDGET_IMAGE: ( + guildId: bigint, + style?: + | "shield" + | "banner1" + | "banner2" + | "banner3" + | "banner4", + ) => { + let url = `/guilds/${guildId}/widget.png?`; + + if (style) { + url += `style=${style}`; + } + + return url; + }, + GUILD_EMOJI: (guildId: bigint, emojiId: bigint) => { + return `/guilds/${guildId}/emojis/${emojiId}`; + }, + GUILD_EMOJIS: (guildId: bigint) => { + return `/guilds/${guildId}/emojis`; + }, + // TODO: move this away + GUILD_ICON: (guildId: bigint, icon: string) => { + return `${baseEndpoints.CDN_URL}/icons/${guildId}/${icon}`; + }, + GUILD_INTEGRATION: (guildId: bigint, integrationId: bigint) => { + return `/guilds/${guildId}/integrations/${integrationId}`; + }, + GUILD_INTEGRATION_SYNC: (guildId: bigint, integrationId: bigint) => { + return `/guilds/${guildId}/integrations/${integrationId}/sync`; + }, + GUILD_INTEGRATIONS: (guildId: bigint) => { + return `/guilds/${guildId}/integrations?include_applications=true`; + }, + GUILD_INVITES: (guildId: bigint) => { + return `/guilds/${guildId}/invites`; + }, + GUILD_LEAVE: (guildId: bigint) => { + return `/users/@me/guilds/${guildId}`; + }, + GUILD_MEMBER: (guildId: bigint, userId: bigint) => { + return `/guilds/${guildId}/members/${userId}`; + }, + GUILD_MEMBERS: (guildId: bigint, options?: ListGuildMembers) => { + let url = `/guilds/${guildId}/members?`; + + if (options !== undefined) { + if (options.limit) url += `limit=${options.limit}`; + if (options.after) url += `&after=${options.after}`; + } + + return url; + }, + GUILD_MEMBER_ROLE: (guildId: bigint, memberId: bigint, roleId: bigint) => { + return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`; + }, + GUILD_MEMBERS_SEARCH: (guildId: bigint, query: string, options?: { limit?: number }) => { + let url = `/guilds/${guildId}/members/search?query=${encodeURIComponent(query)}`; + + if (options) { + if (options.limit !== undefined) url += `&limit=${options.limit}`; + } + + return url; + }, + GUILD_PRUNE: (guildId: bigint, options?: GetGuildPruneCountQuery) => { + let url = `/guilds/${guildId}/prune?`; + + if (options) { + if (options.days) url += `days=${options.days}`; + if (options.includeRoles) url += `&include_roles=${options.includeRoles}`; + } + + return url; + }, + GUILD_REGIONS: (guildId: bigint) => { + return `/guilds/${guildId}/regions`; + }, + GUILD_ROLE: (guildId: bigint, roleId: bigint) => { + return `/guilds/${guildId}/roles/${roleId}`; + }, + GUILD_ROLES: (guildId: bigint) => { + return `/guilds/${guildId}/roles`; + }, + // TODO: move this away + GUILD_SPLASH: (guildId: bigint, icon: string) => { + return `${baseEndpoints.CDN_URL}/splashes/${guildId}/${icon}`; + }, + GUILD_VANITY_URL: (guildId: bigint) => { + return `/guilds/${guildId}/vanity-url`; + }, + GUILD_WEBHOOKS: (guildId: bigint) => { + return `/guilds/${guildId}/webhooks`; + }, + TEMPLATE: (code: string) => { + return `/guilds/templates/${code}`; + }, + GUILD_TEMPLATE: (guildId: bigint, code: string) => { + return `/guilds/${guildId}/templates/${code}`; + }, + GUILD_TEMPLATES: (guildId: bigint) => { + return `/guilds/${guildId}/templates`; + }, + GUILD_PREVIEW: (guildId: bigint) => { + return `/guilds/${guildId}/preview`; + }, + UPDATE_VOICE_STATE: (guildId: bigint, userId?: bigint) => { + return `/guilds/${guildId}/voice-states/${userId ?? "@me"}`; + }, + GUILD_WELCOME_SCREEN: (guildId: bigint) => { + return `/guilds/${guildId}/welcome-screen`; + }, + GUILD_SCHEDULED_EVENTS: (guildId: bigint, withUserCount?: boolean) => { + let url = `/guilds/${guildId}/scheduled-events?`; + + if (withUserCount !== undefined) { + url += `with_user_count=${withUserCount}`; + } + return url; + }, + GUILD_SCHEDULED_EVENT: (guildId: bigint, eventId: bigint, withUserCount?: boolean) => { + let url = `/guilds/${guildId}/scheduled-events/${eventId}`; + + if (withUserCount !== undefined) { + url += `with_user_count=${withUserCount}`; + } + + return url; + }, + GUILD_SCHEDULED_EVENT_USERS: (guildId: bigint, eventId: bigint, options?: GetScheduledEventUsers) => { + let url = `/guilds/${guildId}/scheduled-events/${eventId}/users?`; + + if (options) { + if (options.limit) url += `limit=${options.limit}`; + if (options.withMember) url += `&with_member=${options.withMember}`; + if (options.after) url += `&after=${options.after}`; + if (options.before) url += `&before=${options.before}`; + } + + return url; + }, // Voice - VOICE_REGIONS: () => `${baseEndpoints.BASE_URL}/voice/regions`, + VOICE_REGIONS: () => { + return `/voice/regions`; + }, - INVITE: (inviteCode: string) => `${baseEndpoints.BASE_URL}/invites/${inviteCode}`, + INVITE: (inviteCode: string, options?: GetInvite) => { + let url = `/invites/${inviteCode}?`; - WEBHOOK: (webhookId: bigint, token: string) => `${baseEndpoints.BASE_URL}/webhooks/${webhookId}/${token}`, - WEBHOOK_ID: (webhookId: bigint) => `${baseEndpoints.BASE_URL}/webhooks/${webhookId}`, - WEBHOOK_MESSAGE: (webhookId: bigint, token: string, messageId: bigint) => - `${baseEndpoints.BASE_URL}/webhooks/${webhookId}/${token}/messages/${messageId}`, - WEBHOOK_MESSAGE_ORIGINAL: (webhookId: bigint, token: string) => - `${baseEndpoints.BASE_URL}/webhooks/${webhookId}/${token}/messages/@original`, - WEBHOOK_SLACK: (webhookId: bigint, token: string) => `${baseEndpoints.BASE_URL}/webhooks/${webhookId}/${token}/slack`, - WEBHOOK_GITHUB: (webhookId: bigint, token: string) => - `${baseEndpoints.BASE_URL}/webhooks/${webhookId}/${token}/github`, + if (options) { + if (options.withCounts) url += `with_counts=${options.withCounts}`; + if (options.withExpiration) url += `&with_expiration=${options.withExpiration}`; + if (options.scheduledEventId) url += `&guild_scheduled_event_id=${options.scheduledEventId}`; + } + + return url; + }, + + WEBHOOK: (webhookId: bigint, token: string, options?: { wait?: boolean; threadId?: bigint }) => { + let url = `/webhooks/${webhookId}/${token}?`; + + if (options) { + if (options?.wait !== undefined) url += `wait=${options.wait}`; + if (options.threadId) url += `threadId=${options.threadId}`; + } + + return url; + }, + WEBHOOK_ID: (webhookId: bigint) => { + return `/webhooks/${webhookId}`; + }, + WEBHOOK_MESSAGE: (webhookId: bigint, token: string, messageId: bigint, options?: { threadId?: bigint }) => { + let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`; + + if (options) { + if (options.threadId) url += `threadId=${options.threadId}`; + } + + return url; + }, + WEBHOOK_MESSAGE_ORIGINAL: (webhookId: bigint, token: string, options?: { threadId?: bigint }) => { + let url = `/webhooks/${webhookId}/${token}/messages/@original?`; + + if (options) { + if (options.threadId) url += `threadId=${options.threadId}`; + } + + return url; + }, + WEBHOOK_SLACK: (webhookId: bigint, token: string) => { + return `/webhooks/${webhookId}/${token}/slack`; + }, + WEBHOOK_GITHUB: (webhookId: bigint, token: string) => { + return `/webhooks/${webhookId}/${token}/github`; + }, // Application Endpoints - COMMANDS: (applicationId: bigint) => `${baseEndpoints.BASE_URL}/applications/${applicationId}/commands`, - COMMANDS_GUILD: (applicationId: bigint, guildId: bigint) => - `${baseEndpoints.BASE_URL}/applications/${applicationId}/guilds/${guildId}/commands`, - COMMANDS_PERMISSIONS: (applicationId: bigint, guildId: bigint) => - `${endpoints.COMMANDS_GUILD(applicationId, guildId)}/permissions`, - COMMANDS_PERMISSION: (applicationId: bigint, guildId: bigint, commandId: bigint) => - `${endpoints.COMMANDS_GUILD(applicationId, guildId)}/${commandId}/permissions`, - COMMANDS_ID: (applicationId: bigint, commandId: bigint) => - `${baseEndpoints.BASE_URL}/applications/${applicationId}/commands/${commandId}`, - COMMANDS_GUILD_ID: (applicationId: bigint, guildId: bigint, commandId: bigint) => - `${baseEndpoints.BASE_URL}/applications/${applicationId}/guilds/${guildId}/commands/${commandId}`, + COMMANDS: (applicationId: bigint) => { + return `/applications/${applicationId}/commands`; + }, + COMMANDS_GUILD: (applicationId: bigint, guildId: bigint) => { + return `/applications/${applicationId}/guilds/${guildId}/commands`; + }, + COMMANDS_PERMISSIONS: (applicationId: bigint, guildId: bigint) => { + return `/applications/${applicationId}/guilds/${guildId}/commands/permissions`; + }, + COMMANDS_PERMISSION: (applicationId: bigint, guildId: bigint, commandId: bigint) => { + return `/applications/${applicationId}/guilds/${guildId}/commands/${commandId}/permissions`; + }, + COMMANDS_ID: (applicationId: bigint, commandId: bigint, withLocalizations?: boolean) => { + let url = `/applications/${applicationId}/commands/${commandId}?`; + + if (withLocalizations !== undefined) { + url += `withLocalizations=${withLocalizations}`; + } + + return url; + }, + COMMANDS_GUILD_ID: (applicationId: bigint, guildId: bigint, commandId: bigint, withLocalizations?: boolean) => { + let url = `/applications/${applicationId}/guilds/${guildId}/commands/${commandId}?`; + + if (withLocalizations !== undefined) { + url += `with_localizations=${withLocalizations}`; + } + + return url; + }, // Interaction Endpoints - INTERACTION_ID_TOKEN: (interactionId: bigint, token: string) => - `${baseEndpoints.BASE_URL}/interactions/${interactionId}/${token}/callback`, - INTERACTION_ORIGINAL_ID_TOKEN: (interactionId: bigint, token: string) => - `${baseEndpoints.BASE_URL}/webhooks/${interactionId}/${token}/messages/@original`, - INTERACTION_ID_TOKEN_MESSAGE_ID: (applicationId: bigint, token: string, messageId: bigint) => - `${baseEndpoints.BASE_URL}/webhooks/${applicationId}/${token}/messages/${messageId}`, + INTERACTION_ID_TOKEN: (interactionId: bigint, token: string) => { + return `/interactions/${interactionId}/${token}/callback`; + }, + INTERACTION_ORIGINAL_ID_TOKEN: (interactionId: bigint, token: string) => { + return `/webhooks/${interactionId}/${token}/messages/@original`; + }, + INTERACTION_ID_TOKEN_MESSAGE_ID: (applicationId: bigint, token: string, messageId: bigint) => { + return `/webhooks/${applicationId}/${token}/messages/${messageId}`; + }, // User endpoints - USER: (userId: bigint) => `${baseEndpoints.BASE_URL}/users/${userId}`, - USER_BOT: () => `${baseEndpoints.BASE_URL}/users/@me`, - USER_GUILDS: () => `${baseEndpoints.BASE_URL}/@me/guilds`, - USER_AVATAR: (userId: bigint, icon: string) => `${baseEndpoints.CDN_URL}/avatars/${userId}/${icon}`, - USER_DEFAULT_AVATAR: (icon: number) => `${baseEndpoints.CDN_URL}/embed/avatars/${icon}.png`, - USER_DM: () => `${baseEndpoints.BASE_URL}/users/@me/channels`, - USER_CONNECTIONS: () => `${baseEndpoints.BASE_URL}/users/@me/connections`, - USER_NICK: (guildId: bigint) => `${GUILDS_BASE(guildId)}/members/@me`, + USER: (userId: bigint) => { + return `/users/${userId}`; + }, + USER_BOT: () => { + return `/users/@me`; + }, + USER_GUILDS: () => { + return `/@me/guilds`; + }, + // TODO: move this away + USER_AVATAR: (userId: bigint, icon: string) => { + return `${baseEndpoints.CDN_URL}/avatars/${userId}/${icon}`; + }, + // TODO: move this away + USER_DEFAULT_AVATAR: (icon: number) => { + return `${baseEndpoints.CDN_URL}/embed/avatars/${icon}.png`; + }, + USER_DM: () => { + return `/users/@me/channels`; + }, + USER_CONNECTIONS: () => { + return `/users/@me/connections`; + }, + USER_NICK: (guildId: bigint) => { + return `/guilds/${guildId}/members/@me`; + }, // Discovery Endpoints - DISCOVERY_CATEGORIES: () => `${baseEndpoints.BASE_URL}/discovery/categories`, - DISCOVERY_VALID_TERM: () => `${baseEndpoints.BASE_URL}/discovery/valid-term`, - DISCOVERY_METADATA: (guildId: bigint) => `${GUILDS_BASE(guildId)}/discovery-metadata`, - DISCOVERY_SUBCATEGORY: (guildId: bigint, categoryId: number) => - `${GUILDS_BASE(guildId)}/discovery-categories/${categoryId}`, + DISCOVERY_CATEGORIES: () => { + return `/discovery/categories`; + }, + DISCOVERY_VALID_TERM: (term: string) => { + return `/discovery/valid-term?term=${term}`; + }, + DISCOVERY_METADATA: (guildId: bigint) => { + return `/guilds/${guildId}/discovery-metadata`; + }, + DISCOVERY_SUBCATEGORY: (guildId: bigint, categoryId: number) => { + return `/guilds/${guildId}/discovery-categories/${categoryId}`; + }, // OAuth2 - OAUTH2_APPLICATION: () => `${baseEndpoints.BASE_URL}/oauth2/applications/@me`, + OAUTH2_APPLICATION: () => { + return `/oauth2/applications/@me`; + }, // Stage instances - STAGE_INSTANCES: () => `${baseEndpoints.BASE_URL}/stage-instances`, - STAGE_INSTANCE: (channelId: bigint) => `${baseEndpoints.BASE_URL}/stage-instances/${channelId}`, + STAGE_INSTANCES: () => { + return `/stage-instances`; + }, + STAGE_INSTANCE: (channelId: bigint) => { + return `/stage-instances/${channelId}`; + }, // Misc Endpoints - NITRO_STICKER_PACKS: () => `${baseEndpoints.BASE_URL}/sticker-packs`, + NITRO_STICKER_PACKS: () => { + return `/sticker-packs`; + }, }; export const SLASH_COMMANDS_NAME_REGEX = /^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u;