I'm building a discord.js v13.6.0 music bot and everything is working except this code
const { QueryType } = require('discord-player');
module.exports = {
name: 'play',
aliases: ['p'],
utilisation: '{prefix}play [song name/URL]',
voiceChannel: true,
async execute(client, message, args) {
if (!args[0]) return message.channel.send(`${message.author}, Write the name of the music you want to search. ❌`);
const res = await client.player.search(args.join(' '), {
requestedBy: message.member,
searchEngine: QueryType.AUTO
});
if (!res || !res.tracks.length) return message.channel.send(`${message.author}, No results found! ❌`);
const queue = await client.player.createQueue(message.guild, {
metadata: message.channel
});
try {
if (!queue.connection) await queue.connect(message.member.voice.channel);
} catch {
await client.player.deleteQueue(message.guild.id);
return message.channel.send(`${message.author}, I can't join audio channel. ❌`);
}
await message.channel.send(`Your ${res.playlist ? 'Your Playlist' : 'Your Track'} Loading... 🎧`);
res.playlist ? queue.addTracks(res.tracks) : queue.addTrack(res.tracks[0]);
if (!queue.playing) await queue.play();
},
};
When I use this command, the following error occurs:
Unhandled promise rejection: ReferenceError: player is not defined
I'm new to programming, sorry for any silly mistakes, if you need any info don't hesitate to ask
The possibility of such errors appears either by throwing inside of a async function without a catch block or rejecting a promise which didn't had a.catch()
You might be doing:
The solutions are:
await returnsPromise().catch(e => { console.log(e) })
or
2.Use try/ catch block
try {
await returnsPromise()
} catch (error) {
console.log('That did not go well.')
}
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.