From 2c697a4d2dfa2ed58f66754d595f1e8f50eae2a8 Mon Sep 17 00:00:00 2001 From: ayntee Date: Sat, 26 Dec 2020 20:01:41 +0400 Subject: [PATCH] refactor: add gateway version to constants --- src/bot.ts | 7 +++++-- src/util/constants.ts | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 4fa69b282..4ada5ec2b 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -4,7 +4,7 @@ import { DiscordBotGatewayData, EventHandlers, } from "./types/types.ts"; -import { baseEndpoints, endpoints } from "./util/constants.ts"; +import { baseEndpoints, endpoints, GATEWAY_VERSION } from "./util/constants.ts"; import { spawnShards } from "./ws/shard_manager.ts"; export let authorization = ""; @@ -13,7 +13,7 @@ export let botID = ""; export let eventHandlers: EventHandlers = {}; export let botGatewayData: DiscordBotGatewayData; -export let proxyWSURL = "wss://gateway.discord.gg?v=8&encoding=json"; +export let proxyWSURL = `wss://gateway.discord.gg`; export const identifyPayload: IdentifyPayload = { token: "", @@ -48,6 +48,9 @@ export async function startBot(config: BotConfig) { endpoints.GATEWAY_BOT, ) as DiscordBotGatewayData; + // Explicitly append gateway version and encoding + botGatewayData.url += `?v=${GATEWAY_VERSION}&encoding=json`; + proxyWSURL = botGatewayData.url; identifyPayload.token = config.token; identifyPayload.intents = config.intents.reduce( diff --git a/src/util/constants.ts b/src/util/constants.ts index 251e97a46..061676c2b 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -4,6 +4,9 @@ export const BASE_URL = "https://discord.com/api"; /** https://discord.com/developers/docs/reference#api-versioning-api-versions */ export const API_VERSION = 8; +/** https://discord.com/developers/docs/topics/gateway#gateways-gateway-versions */ +export const GATEWAY_VERSION = 8; + /** https://discord.com/developers/docs/reference#user-agent */ export const USER_AGENT = "DiscordBot (https://github.com/discordeno/discordeno, v10)";