Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda