Bot不收集赠品持续时间,值错误(discord-giveaways | ms)

时间:2020-05-14 07:23:02

标签: javascript async-await bots discord.js

enter image description here因此,因为该命令仅在将每个选项都放入1条消息“ .sg#bot-test 1m 1 Test”中时才有效,所以该命令适用于args,但现在我试图让bot等待用户的选项,就像您将在屏幕截图中看到的那样,但是在持续时间方面,他给了我错误:UnhandledPromiseRejectionWarning: Error: val is not a non-empty string or a valid number. val={"channelID":"702608643329228821","deleted":false,"id":"710388381846077511","type":"DEFAULT","content":"2d","authorID":"391243477058584588","pinned":false,"tts":false,"nonce":"710388377081348096","system":false,"embeds":[],"attachments":[],"createdTimestamp":1589440188610,"editedTimestamp":null,"webhookID":null,"applicationID":null,"activity":null,"flags":0,"reference":null,"guildID":"672002616372363274","cleanContent":"2d"}

如果您想查看软件包的“工作原理”,https://www.npmjs.com/package/discord-giveaways我将不知道该怎么做。

我的代码部分:

await message.channel.send(`Please provide a duration for the giveaway!`)
            const Messagefilter2 = m => m.author.id === message.author.id;
                let giveawayDuration;
                await message.channel.awaitMessages(Messagefilter2, { max: 1, }).then((collected) => {
                    // Giveaway duration
                    giveawayDuration = collected.first()
                })
            // If the duration isn't valid
            if(!giveawayDuration || isNaN(ms(giveawayDuration))){
                return message.channel.send(':x: You have to specify a valid duration!');
            }

1 个答案:

答案 0 :(得分:0)

错误仅是因为我忘记添加.content,所以应该是if(!giveawayDuration || isNaN(ms(giveawayDuration.content))){