guild-data
v0.2.2
Published
Discord.js guild data management with `nkv.db`.
Downloads
4
Readme
guild-data
Discord.js guild data management with nkv.db
.
Requesting the guild object is not resource heavy as it just checks if a guild with that id exists or not (creates it if it doesn't exist).
Requesting properties is also not resource heavy as it is cached.
Technically will work for DMs, but requires tinkering with the code.
TODO: This but for user data.
TODO: Support DMs.
Example
#!/usr/bin/env node
require("dotenv").config();
const Discord = require("discord.js");
const client = new Discord.Client();
client
.login(process.env.TOKEN)
.then(() => {
console.log("Bot login successful.");
})
.catch((e) => {
console.error("An error occured.");
console.error(e);
process.exit(1);
});
// the `database` argument is useless if you don't want to reuse databases
const gd = require("guild-data")(client, { prefix: "&" });
client.on("message", (message) => {
if (message.author.bot || !message.guild) return;
const gld = gd(message.guild.id);
if (!message.content.startsWith(gld.prefix)) return;
let args = message.content.trim().slice(gld.prefix.length).split(" ");
const command = args.shift();
if (command === "get") {
message.channel.send(gld[args[0]] || "undefined");
} else if (command === "set") {
message.channel.send(
(gld[args[0]] = args[1] || undefined) || "undefined"
);
}
});