Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

240
Vistas
ReferenceError: voice is not defined discord.js

I am trying to make a small Music Bot in Discord.js v16.6 which can play local files, but I got the error:

ReferenceError: voice is not defined

I don't understand why voice is not defined. How can I fix this error?

Here is the part of my code:

  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;  
      })
    });
  }

*I can't supply the whole code because stackoverflow won't allow this

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Discord.js only goes up to version v13.4 as of the time of writing this. The code here looks like it's for version v12. I'm guessing you're on Node.js v16.6.

Regarding the actual issue, you're referencing a variable voice that doesn't exist. See this line

voice.channel.join().then( connection => {

I'm guessing you just meant to reference the variable created directly before this line instead.

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;  
      })
    });
  }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda