🗃️ /credits give is now on mongodb
This commit is contained in:
parent
9ca99874fc
commit
d492f0d506
1 changed files with 17 additions and 12 deletions
|
@ -1,8 +1,8 @@
|
||||||
const { Permissions } = require('discord.js');
|
const { Permissions } = require('discord.js');
|
||||||
|
|
||||||
const db = require('quick.db');
|
const credits = require('../../../helpers/database/models/creditSchema');
|
||||||
|
const debug = require('../../../handlers/debug');
|
||||||
|
|
||||||
const credits = new db.table('credits');
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||||
const embed = {
|
const embed = {
|
||||||
|
@ -24,15 +24,20 @@ module.exports = async (interaction) => {
|
||||||
};
|
};
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
} else {
|
} else {
|
||||||
await credits.add(user.id, amount);
|
await credits
|
||||||
|
.findOneAndUpdate({ userId: user.id }, { $inc: { balance: amount } }, { new: true })
|
||||||
const embed = {
|
.then(async () => {
|
||||||
title: 'Give',
|
const embed = {
|
||||||
description: `Gave ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`,
|
title: 'Give',
|
||||||
color: 0x22bb33,
|
description: `Gave ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`,
|
||||||
timestamp: new Date(),
|
color: 0x22bb33,
|
||||||
footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT },
|
timestamp: new Date(),
|
||||||
};
|
footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT },
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
};
|
||||||
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
})
|
||||||
|
.catch(async (err) => {
|
||||||
|
debug(err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue