Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!