1.0.1 • Published 2 years ago

@purplet/gateway v1.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

@purplet/gateway

This is a JavaScript implementation for the Discord Gateway API. It is very light, and doesn't do more than is needed. We do not depend on any runtime-specific apis, but rather the fetch and WebSocket standard APIs, meaning this client can run in Node.js (with polyfills), and in Bun.js.

Basic Example:

import { Gateway } from '@purplet/gateway';
import { GatewayIntentBits } from 'discord-api-types/gateway';

const client = new Gateway({
  intents: GatewayIntentBits.GuildMessages,
  token: process.env.token
});

client.on('MESSAGE_CREATE', message => {
  console.log(message);
});

Installing

@purplet/gateway only a peer-dependency on discord-api-types so you we do not have to bump this package when types change slightly. We also utilize zlib-sync for compression and erlpack for encoding (these don't work on bun yet).

pnpm install @purplet/gateway discord-api-types
# or
bun add @purplet/gateway discord-api-types

Node.js support

Until v18, node.js does not support fetch, and no version of node has WebSocket built-in. We provide another package, @purplet/polyfill which polyfills these APIs for you:

import '@purplet/polyfill';
import { Gateway } from '@purplet/gateway';
// ...