我是 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);
};
});
uj5u.com熱心網友回復:
在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
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/488505.html
