dispose .js不会做它应该做的事情



与我的机器人,我有提款和存款设置,但我有一个小错误或问题,可能有编码稍微错误,但当我试图存入100或任何数字时,它说存款必须是一个孔号码。

const profileModel = require("../models/profileSchema");
module.exports = {
name: "deposit",
aliases: ["dep"],
permissions: [],
description: "Deposit gold into your bank!",
async execute(message, args, cmd, client, discord, profileData) {
const amount = args[0];
if (amount % 1 != 0 || amount <= 0) return message.channel.send("Deposit amount must be a whole number");
try {
if (amount > profileData.gold) return message.channel.send(`You don't have that amount of gold to deposit`);
await profileModel.findOneAndUpdate(
{
userID: message.author.id,
},
{
$inc: {
gold: -amount,
bank: amount,
},
}
);
return message.channel.send(`You deposited ${amount} of gold into your bank`);
} catch (err) {
console.log(err);
}
},
};

取款和存款设置相同,只是更改了金额位而不是-它的+

有一种更好的方法来执行withdrawdeposit命令,我不知道为什么你需要得到一个整数来实现它。我把你的代码修改得更简单、更清晰。

const amount = parseFloat(args[0]); // Your current code: const amount = args[0];
//if (amount % 1 != 0 || amount <= 0) return message.channel.send("Deposit amount must be a whole number");
try {
// > = Greater than and < = Less than.
if (amount > profileData.gold) return message.channel.send(`You don't have that amount of gold to deposit`);
// await profileModel.findOneAndUpdate(
//     {
//     userID: message.author.id,
//     },
//     {
//     $inc: {
//         gold: -amount,
//         bank: amount,
//     },
//     }
// );
await profileModel.findOneAndUpdate(
{
userID: message.author.id,
},
{ $inc: { gold: amount } },
async (err, data) => {
if (data) {
//No data returns a message
} else {
(data.bank += amount), (data.gold -= amount);
return message.channel.send(`You deposited ${amount} of gold into your bank`);
}
}
);
} catch (err) {
console.log(err);
}

parseFloat()

1e0 = 1
1e1 = 10
1e2 = 100
1e3 = 1,000
1e4 = 10,000
and so on

最新更新