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

belua

v2.2.1

Published

A Lightweight Library for easy interacting with the discord.js library

Downloads

6

Readme

Belua

Belua is a framework built for all the discord fans who wanted to create a bot, now possible!

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

You'll need discord.js^14 for this package

npm install discordjs@14

Installing

To start, create a directory for the app and enter it

mkdir myDiscordBot
cd myDiscordBot

Then, create a package.json with

npm init --yes

Then, install the belua package

npm install belua

Usage

Start with a very simple boiler-plate code

import { beluaClient } from 'belua'

const client = new beluaClient(process.env.MY_TOKEN)

This code Imports the beluaClient class from the module and creates an instance of it.

Command Usage

Once the client is initialised, you can start adding commands to it.

import { beluaClient, beluaCommand, beluaCommandData } from 'belua'

// Some Prerequisites
function sleep(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}

let myClient = new beluaClient(process.env.MY_TOKEN)


await sleep(2000) //Ensure client has initialised

myClient.setCommand(new beluaCommand(
  'ping', 
  new beluaCommandData('ping', 'Responds with Pong!'), ((i) => {
  i.reply('Pong!')
})))


await myClient.registerCommands() // Register Commands

This code does the following

  • Import the neccesary classes
  • Sets up a sleep function and uses it to ensure the client has initialised
  • Creates a new command called ping that has a name, description and a execution function that handles the command.
  • Registers the commands with registerCommands()

Message Events

import { beluaClient } from 'belua'

const client = new beluaClient(process.env.MY_TOKEN)

client.on('messageCreate', (m) => {
  if (m.getData().content == '!ping') {
    m.reply('Pong!'); // Respond
  } else if (m.getData().content == '!react') {
    m.react('👍'); // React
  } else if (m.getData().content == '!data') {
    m.reply(m.getData()); // The 'm' argument is a 'beluaMessage' class, so it has unique functions
  } else if (m.getData().content == '!delete') {
    m.reply('Message Deleted!'); // Replying after deleting will throw a 404 error
    m.delete();
  }
})
  • This sets up an event listener for the messageCreate event.

Furthur Reading

The Official Docs is currently being built, so please be patient!

Notes

  • This module supports both cjs and esm format

    const beluaClient = require('belua'); // This Works! (CJS)
    import beluaClient from 'belua' // This also works! (ESM)

    This feature was recently added in the 2.x update

  • client.keepAlive() is an experimental function that attemps to keep the process alive

import { beluaClient } from 'belua';
const client = new beluaClient(process.env.MY_TOKEN)
client.keepAlive() //Experimental
// WOrks only in ESM.

Deployment

To Run,

node .

This starts up the node server. Your Discord bot should be up and running now! But before running, it is recommended to test the build

npm explore belua -- npm run test

This tests the current build

Built With

  • DiscordJS - Built using the discord javascript framework
  • JSDOC - Used for Code Comments!

Versioning

We use SemVer for versioning.

Authors

License

This project is licensed under the MIT License. For more details, check out our license!

Change Log

#todo - Fix webhook errors
#todo Add More Functionality

  • 2.2.1 - Fixed a Message Bug
  • 2.1.0 - Added messgae.delete() & client.keepAlive() (Refer to notes)
  • 2.0.0 - Added Support for CJS syntax
  • 1.3.0 - Reaction features (Added Message Class)
  • 1.2.0 - Added webhook functionalities (beluaWebhook)
  • 1.1.0 - Added functionality for on & once events
  • 1.0.0 - Release