【发布时间】:2019-05-25 03:53:03
【问题描述】:
我正在创建一个不和谐机器人,我想为它创建一个“警告”命令,以在不和谐服务器中的用户行为不端时警告他们。但是,当我运行代码并尝试命令时,它只运行到一半,弹出未处理的承诺拒绝消息,说我还没有定义我的message.channel.find() 函数,即使我已经完全定义了它。
对于某些背景,我正在用 javascript 对这个机器人进行编码,node.js 更具体。我也在使用 discord.js 库。我尝试重新启动我的代码,重新输入括号内的内容,甚至尝试重新格式化几次。但是,这些都没有奏效。我已包含我的代码以帮助大家更好地理解我的问题。
// Here is where it starts to get shakey
let firstslice = message.content.slice(6);
let membertag = membertobewarned.tag;
let reason = firstslice.slice(membertag);
message.channel.send("Second debugging check, check!");
// Here is where it stops working, and the line below this text is where I
// am getting unhandled promise rejection errors from.
let warnchannel = message.channel.find(`name`, "logs");
if (message.author.bot) return;
if (!message.author.hasPermission("MANAGE_MESSAGES")) return message.channel.send("Sorry, but you do not have permission to use this command.");
if (!membertobewarned.hasPermission("MANAGE_MESSAGES")) return message.channel.send("Sorry, but you cannot warn this member.");
message.channel.send("Third debugging thing, check!");
let warnembed = new Discord.RichEmbed()
.setDescription("Warning")
.setColor("#FFA500")
.addField("User:", membertobewarned)
.addField("Warned By:", commanduser)
.addField("For Reason:", reason)
.addField("Time:", timewarned);
warnchannel.send(warnembed);
message.channel.send("I'm all done!");
应该发生的事情是机器人将获取消息发送的渠道、警告谁、谁警告了那个人、他们的提及以及警告的原因。
然后它将获取该信息,并将其编译为不和谐 RichEmbed,然后将其发送到 #logs 频道。
但是,实际发生的情况是,当命令运行时,它会获取所有信息,然后在检查#logs 频道的地方,它会抛出错误:
UnhandledPromiseRejectionWarning TypeError: message.channel.find is not a function.
我希望能够弄清楚为什么会出现此错误,以及如何解决它。感谢大家阅读本文,我希望你们都能尽快帮助我,并度过美好的一天。
【问题讨论】:
标签: javascript node.js discord.js