![](/img/trans.png)
[英]i am trying to make a discord bot using discord.js and im making an even handler but im getting this error
[英]Im trying to make a discord music bot, but every time i run the code i get message is not defined error
我是 js 的新手,我想制作一个音乐不和谐机器人。 这段代码大约在一个小时前工作,没有队列系统,所以我尝试添加一个。 代码坏了,所以我删除了我所做的更改,错误仍然存在。 我仍然收到“ReferenceError:消息未定义”有人知道问题是什么吗?
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);
};
});
在client.on
函数中,您正在使用消息对象,但您已将对象命名为msg
。 我认为你需要改变这一点。 所以它看起来像这样:
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);
};
});
改变的是 2 个message
对象被重命名为msg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.