npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

flarecord

v0.0.3

Published

discord gateway client for cloudflare workers. built with typescript and optimized for durable objects.

Readme

flarecord 🌥️

discord gateway client for cloudflare workers. built with typescript and optimized for durable objects.

installation

npm install flarecord

import

import { DiscordClient, GatewayIntents, MessageHelper } from "flarecord";

flarecord uses source files by default for cloudflare workers.

how it works

flarecord connects to discord's gateway api using websockets. it runs inside cloudflare durable objects which provide:

  • persistent websocket connections
  • automatic reconnection with exponential backoff
  • session resumption after disconnections
  • heartbeat management via durable object alarms
  • state persistence across restarts

the library handles all the complexity of the discord gateway protocol automatically. you just provide a token and intents, and it manages connections, heartbeats, and reconnections.

what it supports

  • discord gateway v10 protocol
  • all gateway intents
  • automatic reconnection
  • session resumption
  • heartbeat management
  • message events
  • interaction events
  • all discord gateway events
  • typescript support

example

import { DurableObject } from "cloudflare:workers";
import { DiscordClient, GatewayIntents, MessageHelper } from "flarecord";
import type { DurableObjectState } from "@cloudflare/workers-types";

export interface Env {
  DISCORD_BOT_TOKEN: string;
}

export class MyBot extends DurableObject<Env> {
  private client: DiscordClient;
  private messageHelper: MessageHelper | null = null;

  constructor(ctx: DurableObjectState, env: Env) {
    super(ctx, env);
    this.client = new DiscordClient(ctx, {
      token: env.DISCORD_BOT_TOKEN,
      intents: GatewayIntents.GUILDS | GatewayIntents.GUILD_MESSAGES | GatewayIntents.MESSAGE_CONTENT,
      onReady: (data) => {
        console.log(`bot ready: ${data.user.username}`);
        this.messageHelper = new MessageHelper(env.DISCORD_BOT_TOKEN);
      },
      onMessage: (data) => {
        if (data._gatewayMetadata?.event !== "MESSAGE_CREATE") return;
        
        const message = data as {
          author?: { bot?: boolean };
          content?: string;
          channel_id?: string;
        };

        if (message.author?.bot || !message.channel_id || !this.messageHelper) return;

        if (message.content === "!ping") {
          this.messageHelper.send(message.channel_id, "pong!");
        }
      },
    });
  }

  async fetch(request: Request): Promise<Response> {
    return this.client.fetch(request);
  }

  async alarm(): Promise<void> {
    return this.client.alarm();
  }
}

configuration

const client = new DiscordClient(ctx, {
  token: "your-bot-token",
  intents: GatewayIntents.GUILDS | GatewayIntents.GUILD_MESSAGES,
  storageKey: "gatewayState", // optional
  onReady: (data) => { /* handle ready */ },
  onMessage: (data) => { /* handle messages */ },
  onError: (error) => { /* handle errors */ },
  onDispatch: (event, data) => { /* handle all events */ },
});

intents

use the GatewayIntents enum to specify which events you want:

import { GatewayIntents } from "flarecord";

const intents = 
  GatewayIntents.GUILDS |
  GatewayIntents.GUILD_MESSAGES |
  GatewayIntents.MESSAGE_CONTENT;

available intents: GUILDS, GUILD_MEMBERS, GUILD_MODERATION, GUILD_EMOJIS_AND_STICKERS, GUILD_INTEGRATIONS, GUILD_WEBHOOKS, GUILD_INVITES, GUILD_VOICE_STATES, GUILD_PRESENCES, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, GUILD_MESSAGE_TYPING, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS, DIRECT_MESSAGE_TYPING, MESSAGE_CONTENT, GUILD_SCHEDULED_EVENTS, AUTO_MODERATION_CONFIGURATION, AUTO_MODERATION_EXECUTION, GUILD_MESSAGE_POLLS, DIRECT_MESSAGE_POLLS.

sending messages

use MessageHelper to send messages, embeds, buttons, and more:

import { MessageHelper } from "flarecord";

const helper = new MessageHelper(token);

// send text
await helper.send(channelId, "hello!");

// send embed
const embed = {
  title: "title",
  description: "description",
  color: 0x00ff00,
};
await helper.send(channelId, embed);

// send button
const button = {
  type: 2,
  style: 1,
  custom_id: "button_id",
  label: "click me",
};
const row = {
  type: 1,
  components: [button],
};
await helper.send(channelId, row);

// reply to message
await helper.reply(channelId, messageId, guildId, "reply text");

requirements

  • cloudflare workers runtime
  • durable objects enabled
  • discord bot token

license

mit