Discord bot enter the voice channel, but it doesn't play any audio

191 Views Asked by At

My discord bot that i'm creating it doesn't play any audio when he joins a voice channel, this is my code.

What i want it is to get the youtube url from the message and plays it. (I'm totally new to javascript so idk if the code is right?)

const { Distube } = require('distube')
const distube = require('distube').Distube
const { joinVoiceChannel, createAudioPlayer } = require('@discordjs/voice')
const player = createAudioPlayer()

module.exports = (client) => {

    const targetChannelId = '431197967337390081'
    const prefix = '-'
    
    client.on('messageCreate', msg => {

        if (msg.channel.id === targetChannelId) {
            if (msg.content.startsWith(prefix)) {
                const command = msg.content.slice(prefix.length).split(' ')[0]
                const args = msg.content.slice(prefix.length).split(' ')[1]

                if (command === 'play') {
                    const connection = joinVoiceChannel({
                        channelId: msg.member.voice.channel.id,
                        guildId: '354279496502738947',
                        adapterCreator: msg.guild.voiceAdapterCreator,
                    }).subscribe(audioPlayer)
                }
            }
        }
    })
}
0

There are 0 best solutions below