Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

javascript - 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. 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(). 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). (rejection id: 1) (node:2052) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

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! 
Hosted by **${message.author}**
Time: **${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.

question from:https://stackoverflow.com/questions/65601775/discord-js-bot-giveaway-commandunhandledpromiserejectionwarning

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...