@purplet/gateway
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@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';
// ...

Package Sidebar

Install

npm i @purplet/gateway

Weekly Downloads

1

Version

1.0.1

License

Apache-2.0

Unpacked Size

52.4 kB

Total Files

19

Last publish

Collaborators

  • clembs
  • davecaruso