skick1234 / DisTube

A powerful Discord.js module for simplifying music commands and effortless playback of various sources with integrated audio filters.
https://distube.js.org
MIT License
423 stars 94 forks source link

TypeError: Cannot read properties of undefined (reading 'paused') #162

Closed unloopedmido closed 3 years ago

unloopedmido commented 3 years ago

Please describe your problem in as much detail as possible: I would like to make my play command check if the queue is paused, And if it is, it'll resume it just like how its done with bots like Rythm. After reading the docs, I found queue.paused which is a boolean. Can I know what I'm doing wrong here?

Error:

TypeError: Cannot read properties of undefined (reading 'paused')

Code:

 const queue = this.bot.player.getQueue(interaction.guildId!)
        if(queue.paused) {
            const queue = this.bot.player.getQueue(interaction.guildId!)

            this.bot.player.resume(interaction.guildId!)
        } else {
            const search = interaction.options.getString('track')
            const ChannelID = interaction.channelId;
            const Channel = this.bot.client.channels.cache.get(ChannelID);
            const channel = interaction.member.voice.channel;
            const member = interaction.member;
            if (!channel) {
                return interaction.reply('❌ **You have to be in a voice channel to use this command.**')
            }
            await interaction.reply(`🎵 **Searching** 🔎 \`${search}\``)
            await this.bot.player.playVoiceChannel(channel, search, {
                textChannel: interaction.channel as any,
                member
            });
        }

Further information:

skick1234 commented 3 years ago

Simply because there is no queue (no playing/paused queue) in this guild. That why queue is undefined (Learn how to read js error) image