MenuDocs / erela.js

An easy-to-use Lavalink client for NodeJS.
Apache License 2.0
194 stars 80 forks source link

player.queue is undefined #132

Closed Anime-Forevere closed 3 years ago

Anime-Forevere commented 3 years ago

Hello! I started migrating my bot to discord.js version 13.1.0 and now I get this error:

player.queue.add(song)
                   ^

TypeError: Cannot read property 'queue' of undefined

My code:

module.exports = {
    description: "Music commands",
    options: [{
        name: "play",
        description:"Plays a song.",
        type:1,
        options: [{
            name: "song",
            description:"A song name or URL",
            type:3,
            required:true
        }],
    }],
    testOnly:true,
    execute: async ({ interaction, args, client }) => {
        let command = args.getSubcommand()
        if(command === "play")
        {
            let song = args.getString("song")
            let player;
            try{
                player = await client.manager.get(interaction.guild)
            } catch (err) {
                player = await client.manager.create({
                    guild: interaction.guild.id,
                    voiceChannel: interaction.member.voice.channel.id,
                    textChannel: interaction.channel.id,
                })
                await player.connect()
            }
            if(song.toLowerCase().includes(`lofi`) && song.toLowerCase().includes(`hip`) || song.toLowerCase().includes(`hop`)){
                if(song.toLowerCase().includes(`relax`) || song.toLowerCase().includes(`study`)){
                    let res = await client.manager.search(`https://www.youtube.com/watch?v=5qap5aO4i9A`, interaction.user)
                    song = res.tracks[0];
                } else if(song.toLowerCase().includes(`sleep`) || song.toLowerCase().includes(`chill`)){
                    let res =  await client.manager.search(`https://www.youtube.com/watch?v=DWcJFNfaw9c`, interaction.user)
                    song = res.tracks[0];
                } else {
                    let res = await client.manager.search(`https://www.youtube.com/watch?v=5qap5aO4i9A`, interaction.user)
                    song = res.tracks[0]
                }
            } else if(song.toLowerCase().includes(`radio`)) {
                let res = await client.manager.search(
                    song,
                    interaction.user,
                )
                let stream = false;
                let i = 0;
                do {
                    if(res.tracks[i])
                    {
                        stream = true;
                        song = res.tracks[i];
                    }
                    else
                    {
                        i += 1
                    }
                }while(!stream)
            } else {
                song = await client.manager.search(song, interaction.user).tracks[0]
            }
            if(!player?.queue) {interaction.reply(`Playing ${song.title} now!`)}else{intreaction.reply(`Added ${song.title} to queue!`)}
            player.queue.add(song)
            if (!player.playing && !player.paused && !player.queue.size) player.play();
            if (!player.playing && !player.paused && player.queue.totalSize === res.tracks.length)player.play();
        }
    },
};

If it breaks because of new discord.js, is there fix released already/going to be released soon?

Anime-Forevere commented 3 years ago

Forgot to add, bot doesn't even connect to voice channel.

Spiderjockey02 commented 3 years ago

player = await client.manager.get(interaction.guild) doesn't error but just causes player to be undefined. so instead of the try catch statement just add an if statement to check that player is undefined or not

Anime-Forevere commented 3 years ago

Thanks, it worked!