UnhandledPromiseRejectionWarning: ReferenceError: member is not defined discord.js
Posted
技术标签:
【中文标题】UnhandledPromiseRejectionWarning: ReferenceError: member is not defined discord.js【英文标题】: 【发布时间】:2020-04-27 17:37:20 【问题描述】:我正在使用 discord.js 制作机器人,但当我尝试制作音乐机器人时,我不断收到此错误??我不知道如何定义成员。它甚至也不会加入频道或明显播放音乐,唯一有效的是告诉机器人继续所需链接的功能
let args = message.content.substring(prefix.length).split(" ");
switch (args[0])
case 'play':
function play(connection, message)
var server = severs[message.guild.id];
server.dispatcher = connection.playStream(ytdl(server.queue[0], filter: "audio"));
server.queue.shift();
server.dispatcher.on("end", function()
if(server.queue[0])
play(connection, message);
else
connection.disconnect();
);
if(!args[1])
message.channel.send("Link needed!");
return;
if(!message.member.voiceChannel)
message.channel.send("You must be in a channel!");
return;
if(!servers[message.guild.id]) servers[message.guild.id] =
queue: []
;
var server = servers[message.guild.id];
server.queue.push(args[1]);
var server = servers[message.guild.id];
server.queue.push(args[1]);
if(!message.guild.voiceConnection) member.voiceChannel.join().then(function(connection)
play(connection, message);
);
break;
case "skip" :
var server = servers[message.guild.id];
if (server.dispatcher) server.dispatcher.end();
break;
case "stop":
var server = server[message.guild.id];
if(message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
break;
【问题讨论】:
【参考方案1】:错误发生在哪里?但基于:
if(!message.member.voiceChannel)
message.channel.send("You must be in a channel!");
return;
你是说
message.member.voiceChannel.join().then(
而不是
member.voiceChannel.join().then(
【讨论】:
【参考方案2】:我对脚本或 discord.js 了解不多,但是
你可以使用connection.play()
而不是connection.playStream()
【讨论】:
以上是关于UnhandledPromiseRejectionWarning: ReferenceError: member is not defined discord.js的主要内容,如果未能解决你的问题,请参考以下文章
[Unhandled promise rejection: TypeError: null is not an object (evaluating '_reactNativeImageCropPic