mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 17:30:07 +00:00
feat: internal intents resolution (#390)
* better intents typing * Update README.md * Update mod.test.ts * support enum too
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
export interface BotConfig {
|
||||
token: string;
|
||||
compress?: boolean;
|
||||
intents: Intents[];
|
||||
intents: (Intents | keyof typeof Intents)[];
|
||||
eventHandlers?: EventHandlers;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user