Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
Discord.js V13 Player is not defined

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

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

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:

  1. you put your code inside an async function in order to use await calls.
  2. The awaited function fails.

The solutions are:

  1. Either use .catch()

    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.')
}
about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!