简体   繁体   English

Discord.js 机器人赠品命令:UnhandledPromiseRejectionWarning

[英]Discord.js Bot giveaway command:UnhandledPromiseRejectionWarning

I am trying to code a giveaway command but this problem pop up on my face我正在尝试编写赠品命令,但这个问题突然出现在我的脸上

(node:2052) UnhandledPromiseRejectionWarning: TypeError: args[1].endswith is not a function (node:2052) UnhandledPromiseRejectionWarning: Unhandled promise rejection. (node:2052) UnhandledPromiseRejectionWarning: TypeError: args[1].endswith 不是 function (node:2052) UnhandledPromiseRejectionWarning: 未处理的 promise 拒绝。 This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with.catch().此错误源于在没有 catch 块的情况下抛出异步 function 内部,或拒绝未使用.catch() 处理的 promise。 To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode ).要终止未处理的 promise 拒绝的节点进程,请使用 CLI 标志--unhandled-rejections=strict (请参阅https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode )。 (rejection id: 1) (node:2052) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. (拒绝 id:1)(节点:2052)[DEP0018] DeprecationWarning:不推荐使用未处理的 promise 拒绝。 In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.将来,未处理的 promise 拒绝将使用非零退出代码终止 Node.js 进程。

client.on('message', async message => {
  let args = message.content.substring(prefix.length).split(" ")
  if(message.content.startsWith(`${prefix}giveaway`)) {
    let time = args[1]
    if(!time) return message.channel.send('**You did not specify your time!**');
    if(
    !args[1].endsWith('d') &&
    !args[1].endsWith('h') &&
    !args[1].endsWith('m') &&
    !args[1].endsWith('s')
   )
    return message.channel.send('**You need to use d (days), h (hours), m (minutes), s (seconds)**')

let gchannel = message.mentions.channels.first();
if(!gchannel) return message.channel.send('**I can not find this channel!**')

let prize = args.slice(3).join(" ")
if(!prize) return message.channel.send('**What is the prize?**')

message.delete();
gchannel.send(":tada: **NEW GIVEAWAY** :tada:")
let gembed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setTitle('New GIVEAWAY!')
.setDescription(`react with :tada: to enter the giveaway! \nHosted by **${message.author}**\nTime: **${time}**`)
.setTimestamp(Date.now + ms(args[1]))
.setFooter('Will end at:')
let m = await gchannel.send(gembed)
m.react("🎉")
setTimeout(() => {
  if(m.reactions.cache.get("🎉").count <= 1) {
    return message.channel.send('**No enough people reacted for mr to draw a winner!**')
  }

let winner = m.reactions.cache.get("🎉").users.cache.filter((u) => !u.bot).random();
gchannel.send(`CONGRATULATIONS ${winner}! you just won the **${prize}!**`
);
}, ms(args[1]));
  }
   })

any help, please.任何帮助,请。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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