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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@brynjolf/events

v0.0.1

Published

A powerful, decorator-based event system for Discord.js.

Downloads

10

Readme

Brynjolf Events

Easily create Discord.js event listeners without needing a Client variable reference everytime, in Javascript or Typescript. Also includes a powerful listener decorator system that enables stateful, modular listener creation for Typescript users.

Features

  • 💊 Typescript decorators to convert classes into modular listeners
  • 🪩 Create Discord.js event listeners without Client
  • 🪶 Lightweight, zero dependencies
  • 🍰 Extremely easy to use
  • 🧩 Fully documented
  • ⭐ New * event emitted alongside all other events
  • 🧠 Built with Typescript, providing great IDE intellisense

Get Started

  1. Create a Discord.js client
  2. Install Brynjolf Events with npm install @brynjolf/events
  3. Run the quick example below, or skip the tutorial and jump right in

Quick Examples

Modular Listeners

⚠️ Requires Typescript >= v5

Using the power of decorators, you can easily create modular classes to handle events. A class can handle any number of events. The events are only handled once the class is constructed into an object. Unfortunately, Javascript does not officially support decorators yet, so this is a Typescript-only feature for the moment.

approver_example.ts:

import { listener } from "@brynjolf/events"
import type { Message } from "discord.js"

// Reacts with 👍 on the third message received
class MessageApprover {
    private messageCount: number = 0;

    @listener("messageCreate")
    onMessage(message: Message) {
        this.messageCount++;
        if (this.messageCount == 3) message.react("👍");
    }
}

// Construct
new MessageApprover();

index.ts:

import { events } from "@brynjolf/events"
import { Client, IntentsBitField } from "discord.js"

// Create Discord.js client
const client = new Client({ intents: [
    IntentsBitField.Flags.Guilds,
    IntentsBitField.Flags.GuildMessages
]});
client.login("YOUR TOKEN HERE");

// Set client in events system
events.client(client);

No-Client Listeners

✅ Works in Javascript or Typescript

Easily create event listeners without needing an immediate reference to a Client. Just supply a Client once in your main file, and all listeners will work.

message_example.js:

import { events } from "@brynjolf/events"

events.on("messageCreate", message => {
    message.reply("Hello there!");
});

index.js:

import { events } from "@brynjolf/events"
import { Client, IntentsBitField } from "discord.js"

// Import your event files
import "message_example.js";

// Create Discord.js client
const client = new Client({ intents: [
    IntentsBitField.Flags.Guilds,
    IntentsBitField.Flags.GuildMessages,
    IntentsBitField.Flags.MessageContent
]});
client.login("YOUR TOKEN HERE");

// Set client in events system
events.client(client);

All Event

✅ Works in Javascript or Typescript

The all (*) event is emitted when any other event is emitted, providing you the name of the emitted event and its arguments.

import { events } from "@brynjolf/events"

events.on("*", (eventName, args) => {
    console.log(`Event '${eventName}' was triggered.`);
});

// Message sent:
// => "Event 'messageCreate' was triggered."

// Slash command used:
// => "Event 'interactionCreate' was triggered."

// Message deleted:
// => "Event 'messageDelete' was triggered."

// And so on...

This obviously requires you to create a Discord.js Client and supply it via events.client(), just like the above examples.

Docs

For examples, see the quick examples above. They cover most, if not all, of this package's functionality.

Primary Features →
Typescript Types →
Examples →