Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Im trying to make a discord music bot, but every time i run the code i get message is not defined error

I’m pretty new at js and I wanted to make a music discord bot. This code was working an hour or so ago without a queue system, so i attempted to add one. The code broke, so I deleted the changes I made and the error still persisted. I still get "ReferenceError: message is not defined" does anyone know what the issue is?

const Discord = require('discord.js');
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});
const config = require('./config.json');
client.music = require("discord.js-musicbot-addon");
var queue= new Array();

  client.on("message", (msg) => {
    if (msg.author.bot) return;
    const client = msg.client;
    // Get the command from the message.
    const command = message.substring(musicbot.botPrefix.length).split(/[ \n]/)[0].trim();
    // Get the suffix, the String after the command.
    const suffix = message.substring(musicbot.botPrefix.length + command.length).trim();
    let prefix = "<3"
    if (msg.content.startsWith(prefix) && command == "play") {
      // pass the Message Object (msg) and the suffix.
        queue.push(msg)
        for(var i=0; i <= queue.length; queue.length--){
        client.music.bot.playFunction(queue[0], suffix);
        }
        queue.splice(0,1);
    };
  });

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

in the client.on function you are using the message object, but you have named the object msg. I think you need to change that. So it will look like this:

const Discord = require('discord.js');
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});
const config = require('./config.json');
client.music = require("discord.js-musicbot-addon");
var queue= new Array();

  client.on("message", (msg) => {
    if (msg.author.bot) return;
    const client = msg.client;
    // Get the command from the message.
    const command = msg.substring(musicbot.botPrefix.length).split(/[ \n]/)[0].trim();
    // Get the suffix, the String after the command.
    const suffix = msg.substring(musicbot.botPrefix.length + command.length).trim();
    let prefix = "<3"
    if (msg.content.startsWith(prefix) && command == "play") {
      // pass the Message Object (msg) and the suffix.
        queue.push(msg)
        for(var i=0; i <= queue.length; queue.length--){
        client.music.bot.playFunction(queue[0], suffix);
        }
        queue.splice(0,1);
    };
  });

What changed is the 2 message objects are renamed to msg

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading