diff --git a/README.md b/README.md index 0f39dc286..6f7ee3c6d 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,11 @@ If you do not wish to use a boilerplate, you may continue reading. Here's a minimal example to get started with: ```typescript -import { Intents, startBot } from "https://deno.land/x/discordeno@10.0.1/mod.ts"; +import { startBot } from "https://deno.land/x/discordeno/mod.ts"; startBot({ token: "BOT TOKEN", - intents: [Intents.GUILDS, Intents.GUILD_MESSAGES], + intents: ["GUILDS", "GUILD_MESSAGES"], eventHandlers: { ready() { console.log("Successfully connected to gateway"); diff --git a/src/bot.ts b/src/bot.ts index b59c69113..017d0c722 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -3,6 +3,7 @@ import { BotConfig, DiscordBotGatewayData, EventHandlers, + Intents, } from "./types/mod.ts"; import { baseEndpoints, endpoints, GATEWAY_VERSION } from "./util/constants.ts"; import { spawnShards } from "./ws/shard_manager.ts"; @@ -54,7 +55,7 @@ export async function startBot(config: BotConfig) { proxyWSURL = botGatewayData.url; identifyPayload.token = config.token; identifyPayload.intents = config.intents.reduce( - (bits, next) => (bits |= next), + (bits, next) => (bits |= typeof next === "string" ? Intents[next] : next), 0, ); identifyPayload.shard = [0, botGatewayData.shards]; @@ -96,7 +97,7 @@ export async function startBigBrainBot(data: BigBrainBotConfig) { } identifyPayload.intents = data.intents.reduce( - (bits, next) => (bits |= next), + (bits, next) => (bits |= typeof next === "string" ? Intents[next] : next), 0, ); diff --git a/src/types/options.ts b/src/types/options.ts index 962c178db..2ec6fd099 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -28,7 +28,7 @@ import { export interface BotConfig { token: string; compress?: boolean; - intents: Intents[]; + intents: (Intents | keyof typeof Intents)[]; eventHandlers?: EventHandlers; } diff --git a/test/mod.test.ts b/test/mod.test.ts index a82632bf5..866fad30f 100644 --- a/test/mod.test.ts +++ b/test/mod.test.ts @@ -22,7 +22,6 @@ import { getMessage, getPins, Guild, - Intents, OverwriteType, pin, removeReaction, @@ -37,7 +36,7 @@ if (!token) throw new Error("Token is not provided"); startBot({ token, - intents: [Intents.GUILD_MESSAGES, Intents.GUILDS], + intents: ["GUILD_MESSAGES", "GUILDS"], }); // Default options for tests