这是我的 index.js 并且我收到此错误(UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“播放”),你能帮我吗?
const Discord = require("discord.js"),
client = new Discord.Client(),
settings = {
prefix: "=",
token: "(my bot's token)"
};
const { Player } = require("discord-player");
const player = new Player(client);
client.player = player;
client.player.on('trackStart', (message, track) => message.channel.send(`Now playing ${track.title}...`))
client.on("ready", () => {
console.log("I'm ready !");
});
client.on("message", async (message) => {
const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === "play") {
let track = await client.Player.play(member.voice.channel, args[0], message.member.user.tag);
message.channel.send(`Currently playing ${track.name}! - Requested by ${track.requestedBy}`);
}
});
client.login(settings.token);
答案 0 :(得分:0)
请记住,JavaScript 变量名称区分大小写。比较您示例中的以下几行:
client.player = player;
let track = await client.Player.play();
尝试将您的呼叫更改为 client.player
而不是 client.Player
。
您甚至可能想将 player
重命名为 currentPlayer
或其他名称,以区分 player
(一个实例)和 Player
(一个类)。