Skip to content

apacheli/whirlybird

Repository files navigation

whirlybird

A JavaScript library for making Discord bots.

Core

Install

Using Bun v1.1.15 (recommended):

$ bun install https://github.com/apacheli/whirlybird

Using Deno v1.44.4:

import * as whirlybird from "https://github.com/apacheli/whirlybird/raw/dev/core/lib.js";

Using Node.js v22.3.0:

$ npm i https://github.com/apacheli/whirlybird

Example

import { CacheClient, GatewayClient, IntentFlags, RestClient } from "whirlybird";

const token = `Bot ${process.env.BOT_TOKEN}`;

const cache = new CacheClient();
const rest = new RestClient(token);

const handleEvent = (event, data) => {
  cache.handleEvent(event, data);

  switch (event) {
    case "MESSAGE_CREATE": {
      if (data.content === "!ping") {
        rest.createMessage(data.channel_id, {
          data: {
            content: "Pong!",
          },
        });
      }
      break;
    }
  }
};

const gateway = new GatewayClient(token, {
  handleEvent,
  identify: {
    intents: IntentFlags.GUILD_MESSAGES | IntentFlags.MESSAGE_CONTENT,
  },
  token,
  url: "wss://gateway.discord.gg",
});

gateway.connect();