Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

asynchronous - Dont know how to fix this error code in my bot discord code. (new to this)

I'm new to this coding thing and I have this code for a discord bot that has a feature that should be able to join the discord call and play music. Whenever I attempted to make the bot join and play music by doing "?play (music) " it joins the call (which is good) but then doesn't play any music and gives me this error code,

"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"

Not sure what to do to fix this, here's my code which I think is affecting the bot.

bot.on("message", async message => {
   const prefix = '?' ;

   const args = message.content. slice(prefix.length).trim().split(/ +/g);
   const command = args.shift().toLowerCase();

    if (command === 'play') {
        let track = await bot.player.play(message.member.voice.channel, args[0], message.member.user.tag);
        message.channel.send(`Currently playing ${track.name}! - Requested by ${track.requestedBy}`); 
    }
    
    if (command === 'stop') {
        let track = await bot.player.stop(message.guild.id);
        message.channel.send(`STOPPED`);
    }
})

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

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...