disclb v0.0.77
Disclb
This is simply a library/add on to discord.js and discord.js-commando that will make your life a lot easier.
A quick disclaimer: the reason the GitHub repo has no files is because this library was originally created for my Discord bot Idle Bee Factory and was made public because why not. In the future, if it gets popular enough, I will put the files there. For now, just use it to post issues.
Features
Usage examples down below.
- Wait for message. A custom class that lets you wait for a message from a user and then runs your handler function.
- Save per user and per guild settings. Uses lowdb to save user settings in any folder of your liking. To avoid corruption, it saves every guild and user in a seperate file. (A queue feature is coming soon so if there is loads of data getting saved every second, it gets added to a queue and all saved at once to avoid corruption).
- Better help/ping commands (and easily customisable for the lazy!)
- Better unknown command responses (and easily customisable for the lazy!)
And more coming soon. Join this discord server and ping me at UnknownSloth#6791 to suggest stuff or report bugs and issues.
Usage
You must initialise disclb with your bot's client. Can be a discord.js or discord.js-commando client.
You no longer need to do this.
Guild and user config
Here is a simple example on what you could do.
let disclb = require('disclb');
disclb.setBaseConfigPath(path.join(__dirname, 'config'));
client.on('guildMemberAdd', (member) => {
disclb.createUserConfig(member.user, {
id: member.user.id,
tag: member.user.tag,
messages: 0
});
});
client.on('message', (msg) => {
let data = disclb.getUserData(msg.author);
data.set("messages", date.get("messages").value() + 1).write();
});
And you can do the same with guilds by changing anywhere it says "User" to "Guild". I made sure to incorporate jsdoc so VSCode intellisense will work with this.
Using waitForMessage
It's quite simple to understant. heres an example:
msg.channel.send("reply with oof");
var wait = new disclb.waitForMessage(msg); // waitForMessage is a class because their will be multiple functions
wait.handler((yes, msg) => { // You can also do (yes, msg, channel, member).
if(msg.content == "oof") {
msg.channel.send("noice"); // The code only gets to this point if: the message content is "oof", it was sent in the original channel, and was sent by the user who sent the original meesage.
yes() // You must run this. If you do not run this, the listener will keep listening and running your handler function.
}
}, this.client);
wait.close(); // gets rid of the listener.
wait = null;
Please note: you must run yes()
or the listener will keep listening and running your handler function.
<waitForMessage>.close()
does not do the same thing as wait = null
it just stops the listener. After running <waitForMessage>.close()
you can supply another handler function and it will start a new listener with your new handler function. This is useful for multi-argument commands such as a ban command which might need a user and a reason.