A npm package for making economy bots.
Forked from discord-mongo-currency (https://www.npmjs.com/package/discord-mongo-currency)
npm i discord-mongo-currency.better
Start off by connecting discord-mongo-currency to MongoDB.
const mongoCurrency = require('discord-mongo-currency.better');
mongoCurrency.connect('MongoURI');
- Update mongoose package to
^6.5.2
- Added withdraw method
- Added giveCoinsBank method
- Added deductCoinsBank method
- Added generateLeaderboardTotal method
- Added generateLeaderboardWallet method
- Added generateLeaderboardBank method
- Finished deposit method
- Bugs fixed
Adds a user to the database.
Deletes a user from the database.
Gives coins to the user's wallet. Adds the user to the database if the user is saved in the database.
Gives coins to the user's bank. Adds the user to the database if the user is saved in the database.
Deducts coins from a user's wallet.
Deducts coins from a user's bank.
Finds the user in the database.
Gives bank space to a user.
Deposits coins from the users wallet.
Generates a leaderboard with the total money of the members.
Generates a leaderboard with the money from the user's wallets.
Generates a leaderboard with the money from the user's bank.
Withdraws coins from the users bank.
const mongoCurrency = require('discord-mongo-currency.better');
const { EmbedBuilder } = require('discord.js');
const user = await mongoCurrency.findUser(interaction.user.id, interaction.guild.id); // Get the user from the database.
const embed = new EmbedBuilder()
.setTitle(`${interaction.user.username}'s Balance`)
.setDescription(`Wallet: ${user.coinsInWallet}\nBank: ${user.coinsInBank}/${user.bankSpace}\nTotal: ${user.coinsInBank + user.coinsInWallet}`);
interaction.reply({ embeds: [embed] });
const mongoCurrency = require('discord-mongo-currency.better');
const randomCoins = Math.floor(Math.random() * 99) + 1; // Random amount of coins.
await mongoCurrency.giveCoins(interaction.user.id, interaction.guild.id, randomCoins);
const mongoCurrency = require('discord-mongo-currency.better');
const { EmbedBuilder } = require('discord.js');
const leaderboard = await db.generateLeaderboardBank(interaction.guild.id, 10); // you can use "generateLeaderboardWallet" too!
const embed1 = new EmbedBuilder()
.setDescription(`Nobody in the leaderboard.`);
if (leaderboard.length < 1) {
return interaction.reply({
embeds: [embed1],
});
}
const mappedLeaderboard = leaderboard.map(
(i) =>
`${
`<@${i.userId}> • ${i.coinsInBank}` ??
`Nobody.`
}`
);
const embed = new EmbedBuilder()
.setTitle(
`${interaction.guild.name} Leaderboard`
)
.setDescription(`${mappedLeaderboard.join("\n")}`);
interaction.reply({
embeds: [embed],
});