简体   繁体   中英

How can I remove [object Promise] from discord.js?

I am making a balance system, and I created a give command. Whenever I give someone some money ($10 for example), their balance shows as "$10 [object Promise]". How can I remove "[object Promise]"?

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

Full command code:

        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');

Even the database has [object promise] at the end

phpMyAdmin screenshot

If moneydb is a Keyv database as it appears in your question, then this line of code:

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

puts a promise into uMA. You are apparently missing an await like this:

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

So, when you do this:

 const money3 = args[0] + uMA;

And uMA is a promise, it tries to make them both into a string and you get the output that contains [object Promise] .

FYI, you can see from the Keyv documentation here that both .set() and .get() return promises.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM