seyfert/packages/ws/README.md
2022-09-07 22:58:11 -05:00

2.0 KiB

@biscuitland/ws

Most importantly, biscuit's ws is:

A standalone gateway to interface Discord, it is meant to be used with a rest manager to send fetch requests to Discord

biscuit

Install (for node18)

npm install @biscuitland/ws
yarn add @biscuitland/ws

Example (GW proxy)

import { ShardManager } from '@biscuitland/ws';
import { DefaultRestAdapter } from '@biscuitland/rest';
import { GatewayIntents } from '@biscuitland/api-types';
import type { DiscordGetGatewayBot, DiscordReady } from '@biscuitland/api-types';

const intents = GatewayIntents.Guilds;
const token = 'your token goes here';
const rest = new DefaultRestAdapter({ token });

const gateway = await rest.get<DiscordGetGatewayBot>('/gateway/bot');

// gateway bot code ↓
const ws = new ShardManager({
    gateway,
    config: { intents, token },
    handleDiscordPayload(shard, payload) {
        if (payload.t === "READY") {
            const data = payload.d as DiscordReady;
            console.log("logged in as:", data.user.username);
            console.log("shard: %d", shard.options.id);
        }
    },
});

await ws.spawns();