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

Time:06-10

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

CodePudding user response:

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

  • Related