Estoy tratando de hacer un pequeño Music Bot en Discord.js v16.6 que pueda reproducir archivos locales, pero recibí el error:
ReferenceError: la voz no está definida
No entiendo por qué la voz no está definida. ¿Cómo puedo solucionar este error?
Aquí está la parte de mi código:
if( isReady && startsWithInList(message.content, settings.commandPlay) ) { isReady = false; const args = message.content.slice(10).trim().split(' '); if( args.length != 1 || !args[0] || args[0] === "" ) { return message.channel.send(settings.warningPlayArgsSentence); } var voiceChannel = message.member.voice.channel; voice.channel.join().then( connection => { const dispatcher = connection.play(settings.filesDir+args[0]+'.mp3') dispatcher.on('finish', () => { voiceChannel.leave(); isReady = true; }) }); }
* No puedo proporcionar el código completo porque stackoverflow no lo permitirá
Discord.js solo sube a la versión v13.4 al momento de escribir esto. El código aquí parece que es para la versión v12. Supongo que estás en Node.js v16.6.
Con respecto al problema real, estás haciendo referencia a una voice
variable que no existe. ver esta línea
voice.channel.join().then( connection => {
Supongo que solo querías hacer referencia a la variable creada directamente antes de esta línea.
if( isReady && startsWithInList(message.content, settings.commandPlay) ) { isReady = false; const args = message.content.slice(10).trim().split(' '); if( args.length != 1 || !args[0] || args[0] === "" ) { return message.channel.send(settings.warningPlayArgsSentence); } var voiceChannel = message.member.voice.channel; // See below for the change voiceChannel.join().then( connection => { const dispatcher = connection.play(settings.filesDir+args[0]+'.mp3') dispatcher.on('finish', () => { voiceChannel.leave(); isReady = true; }) }); }