discord-mongo-plus
v1.0.3
Published
Easy and lightweight MongoDB economy system.
Downloads
8
Maintainers
Readme
discord-mongo-plus
Easy and lightweight MongoDB economy system.
Installation
npm i discord-mongo-plus
Connection
First of all, we fetch the module to the project.
const mongoEconomy = require("discord-mongo-plus")
After that, you need to provide a valid mongo database url, and set it. You can do so by doing:
mongoEconomy.connect('mongodb://...')
Methods
Creating the user
mongoEconomy.create("userid", "guildid") // This is so we can start adding data to this user.
Deleting the user
mongoEconomy.delete("userid", "guildid") // This will remove all the data of the user.
Fetching the users data
mongoEconomy.find("userid", "guildid") // This will fetch the users data.
Adding money to the user
mongoEconomy.add("userid", "guildid", amount) // You can put the amount without a "" or vice versa.
Adding bank space to the user
mongoEconomy.addbankspace("userid", "guildid", amount) // You can put the amount without a "" or vice versa.
Removing money to the user
mongoEconomy.deduct("userid", "guildid", amount) // You can put the amount without a "" or vice versa.
Fetching the leaderboard for a certain guild
mongoEconomy.leaderboard("guildid", amount) // The amount part is the amount of users you would like to show.
Examples
Balance Command
let member = message.mentions.users.first() || message.author;
let user = await mongoEconomy.find(member.id, message.guild.id);
message.channel.send({
embed: {
color: `RANDOM`,
title: `${member.tag}'s Balance`,
description: `Money: ${user.money}\nBank: ${user.bank}\nTotal: ${user.money + user.bank}`
}
})
Leaderboard Command
const leaderboard = await mongoEconomy.leaderboard(message.guild.id, 10)
const lb = leaderboard.map(i => `${bot.users.cache.get(i.userid).tag ? bot.users.cache.get(i.userid).tag : "Nobody"} - ${i.money}`)
if (leaderboard.length < 0) return message.channel.send("Nobody is in the leaderboard!")
message.channel.send({
embed: {
color: `RANDOM`,
description: `${lb.join("\n")}`,
title: `${message.guild.name}'s Leaderboard`
}
})
Help
Go to our Discord Server for help!