-2

我正在制作一个平衡系统,并创建了一个给定命令。每当我给某人一些钱(例如 10 美元)时,他们的余额就会显示为“10 美元 [object Promise]”。如何删除“[object Promise]”?

余额:100 美元 [对象承诺]

完整的命令代码:

        if (command === 'give') {

            if (!args[0]) return message.channel.send('how much are you gonna send?')

            if (isNaN(args[0])) return message.channel.send('format: xd give [amount] [@user]')

            const money = args[0];

            const emb = new Discord.MessageEmbed()
            .setColor('GRAY')
            .setTitle('you gave them the $$')
            .setDescription(`you gave ${message.mentions.users.first().username} the $$$$$$ (` + args[0] + ` to be exact)`)
            .setTimestamp()
            .setFooter('sent to pokimane');

            message.channel.send(emb);

            const money2 = moneyAmount - args[0];

            if (isNaN(money2)) {
                Number(money2);
            }

            moneydb.set(message.author.id, money2);



                        const uMA = moneydb.get(message.mentions.users.first().id);

                        const money3 = args[0] + uMA;

                        moneydb.set(message.mentions.users.first().id, money3);
        }
// keyv connection
const moneydb = new Keyv('mysql://[user and pass]@localhost:3306/money');

连数据库最后都有[object promise]

phpMyAdmin 截图

4

1 回答 1

0

如果moneydb是您的问题中出现的 Keyv 数据库,那么这行代码:

const uMA = moneydb.get(message.mentions.users.first().id);

对 uMA 做出承诺。你显然错过了await这样的:

const uMA = await moneydb.get(message.mentions.users.first().id);

所以,当你这样做时:

 const money3 = args[0] + uMA;

并且uMA是一个承诺,它试图将它们都变成一个字符串,然后你会得到包含[object Promise].

仅供参考,您可以从此处的 Keyv 文档中看到这两个.set().get()return 承诺。

于 2021-05-29T01:01:10.170 回答