belua
v2.2.1
Published
A Lightweight Library for easy interacting with the discord.js library
Downloads
6
Maintainers
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
andesm
formatconst beluaClient = require('belua'); // This Works! (CJS) import beluaClient from 'belua' // This also works! (ESM)
This feature was recently added in the
2.x
updateclient.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
Versioning
We use SemVer for versioning.
Authors
- 10xyz - Github
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 Bug2.1.0
- Addedmessgae.delete()
&client.keepAlive()
(Refer to notes)2.0.0
- Added Support for CJS syntax1.3.0
- Reaction features (Added Message Class)1.2.0
- Added webhook functionalities (beluaWebhook
)1.1.0
- Added functionality foron
&once
events1.0.0
- Release