diff --git a/helpers/channels/createStageInstance.ts b/helpers/channels/createStageInstance.ts index 0c630ce07..429bb2c8a 100644 --- a/helpers/channels/createStageInstance.ts +++ b/helpers/channels/createStageInstance.ts @@ -6,7 +6,7 @@ export async function createStageInstance(bot: Bot, channelId: bigint, topic: st const result = await bot.rest.runMethod( bot.rest, "post", - bot.constants.endpoints.STAGE_INSTANCES, + bot.constants.endpoints.STAGE_INSTANCES(), { channel_id: channelId.toString(), topic, diff --git a/helpers/discovery/getDiscoveryCategories.ts b/helpers/discovery/getDiscoveryCategories.ts index ab60cce94..81059cd26 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.endpoints.DISCOVERY_CATEGORIES(), ); return new Collection( diff --git a/helpers/discovery/validDiscoveryTerm.ts b/helpers/discovery/validDiscoveryTerm.ts index 1e43c0299..ce3cf4ab6 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, + bot.constants.endpoints.DISCOVERY_VALID_TERM(), { term }, ); diff --git a/helpers/guilds/createGuild.ts b/helpers/guilds/createGuild.ts index 97db482d1..0f2582ef9 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.endpoints.GUILDS(), { name: options.name, afk_channel_id: options.afkChannelId, afk_timeout: options.afkTimeout, diff --git a/helpers/guilds/getAvailableVoiceRegions.ts b/helpers/guilds/getAvailableVoiceRegions.ts index 87680c057..52cb3a4fc 100644 --- a/helpers/guilds/getAvailableVoiceRegions.ts +++ b/helpers/guilds/getAvailableVoiceRegions.ts @@ -4,7 +4,7 @@ import { Collection } from "../../util/collection.ts"; /** Returns an array of voice regions that can be used when creating servers. */ export async function getAvailableVoiceRegions(bot: Bot) { - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.VOICE_REGIONS); + const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.VOICE_REGIONS()); return new Collection( result.map((region) => { diff --git a/helpers/members/getDmChannel.ts b/helpers/members/getDmChannel.ts index 41fc8e2f6..aec9a0faf 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.endpoints.USER_DM(), { recipient_id: userId.toString(), }); diff --git a/helpers/misc/editBotProfile.ts b/helpers/misc/editBotProfile.ts index 17d4e8eb4..06b2a8892 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.endpoints.USER_BOT(), { username: options.username?.trim(), avatar, }); diff --git a/helpers/misc/getGatewayBot.ts b/helpers/misc/getGatewayBot.ts index 48db0c207..67e80ca39 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.endpoints.GATEWAY_BOT()); return bot.transformers.gatewayBot(result); } diff --git a/helpers/misc/nitroStickerPacks.ts b/helpers/misc/nitroStickerPacks.ts index dec7ed691..2f26d418b 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.endpoints.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 5fc521a35..47747f49f 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.endpoints.OAUTH2_APPLICATION(), ); return bot.transformers.application(bot, result); diff --git a/rest/restManager.ts b/rest/restManager.ts index 05cfc151c..f8993606f 100644 --- a/rest/restManager.ts +++ b/rest/restManager.ts @@ -15,10 +15,15 @@ import { API_VERSION } from "../util/constants.ts"; export function createRestManager(options: CreateRestManagerOptions) { const version = options.version || API_VERSION; + console.log('url1', baseEndpoints.BASE_URL) + if (options.customUrl) { + console.log('url2', baseEndpoints.BASE_URL) baseEndpoints.BASE_URL = `${options.customUrl}/v${version}`; } + console.log('url3', baseEndpoints.BASE_URL) + return { // current invalid amount invalidRequests: 0, diff --git a/util/constants.ts b/util/constants.ts index ce7aac6f3..b8a9db654 100644 --- a/util/constants.ts +++ b/util/constants.ts @@ -30,7 +30,7 @@ export const endpoints = { GUILDS_BASE, CHANNEL_BASE, - GATEWAY_BOT: `${baseEndpoints.BASE_URL}/gateway/bot`, + GATEWAY_BOT: () => `${baseEndpoints.BASE_URL}/gateway/bot`, // Channel Endpoints CHANNEL_MESSAGE: (channelId: bigint, messageId: bigint) => `${CHANNEL_BASE(channelId)}/messages/${messageId}`, @@ -71,7 +71,7 @@ export const endpoints = { `${CHANNEL_BASE(channelId)}/users/@me/threads/archived/private`, // Guild Endpoints - GUILDS: `${baseEndpoints.BASE_URL}/guilds`, + 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`, @@ -111,7 +111,7 @@ export const endpoints = { `${GUILDS_BASE(guildId)}/scheduled-events/${eventId}/users`, // Voice - VOICE_REGIONS: `${baseEndpoints.BASE_URL}/voice/regions`, + VOICE_REGIONS: () => `${baseEndpoints.BASE_URL}/voice/regions`, INVITE: (inviteCode: string) => `${baseEndpoints.BASE_URL}/invites/${inviteCode}`, @@ -148,30 +148,30 @@ export const endpoints = { // 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_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_DM: () => `${baseEndpoints.BASE_URL}/users/@me/channels`, + USER_CONNECTIONS: () => `${baseEndpoints.BASE_URL}/users/@me/connections`, USER_NICK: (guildId: bigint) => `${GUILDS_BASE(guildId)}/members/@me`, // Discovery Endpoints - DISCOVERY_CATEGORIES: `${baseEndpoints.BASE_URL}/discovery/categories`, - DISCOVERY_VALID_TERM: `${baseEndpoints.BASE_URL}/discovery/valid-term`, + 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}`, // OAuth2 - OAUTH2_APPLICATION: `${baseEndpoints.BASE_URL}/oauth2/applications/@me`, + OAUTH2_APPLICATION: () => `${baseEndpoints.BASE_URL}/oauth2/applications/@me`, // Stage instances - STAGE_INSTANCES: `${baseEndpoints.BASE_URL}/stage-instances`, + STAGE_INSTANCES: () => `${baseEndpoints.BASE_URL}/stage-instances`, STAGE_INSTANCE: (channelId: bigint) => `${baseEndpoints.BASE_URL}/stage-instances/${channelId}`, // Misc Endpoints - NITRO_STICKER_PACKS: `${baseEndpoints.BASE_URL}/sticker-packs`, + NITRO_STICKER_PACKS: () => `${baseEndpoints.BASE_URL}/sticker-packs`, }; export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/;