[英]TypeError: Cannot read property 'find' of undefined discord.js
I was making a command for my discord bot and i counter an error in the process I'm pretty new to programming so forgive me if there was something very simple that i couldn't figure out我正在为我的 discord 机器人发出一个命令,我在这个过程中遇到了一个错误
TypeError: Cannot read property 'find' of undefined
at Object.callback (C:\Users\Aoshey\Downloads\Nol\bot test\modules\setimage.mod.js:11:30)
at ReputationCore.<anonymous> (C:\Users\Aoshey\node_modules\reputation-core\builtin_modules\commands.mod.js:54:33)
at ReputationCore.emit (events.js:314:20)
at ReputationCore.EventEmitter.emit (domain.js:483:12)
at Client.<anonymous> (C:\Users\Aoshey\node_modules\reputation-core\reputationCore.js:35:10)
at Client.emit (events.js:314:20)
at Client.EventEmitter.emit (domain.js:483:12)
at MessageCreateHandler.handle (C:\Users\Aoshey\node_modules\reputation-core\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\Users\Aoshey\node_modules\reputation-core\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:108:65)
at WebSocketConnection.onPacket (C:\Users\Aoshey\node_modules\reputatiocore\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:336:35)
code:代码:
const fsn = require("fs-nextra");
const colors = require("colors");
exports.id = "setimg";
exports.onLoad = api => {
api.commands.add("setimg", (msg) => {
let employeeRole = msg.guild.roles.get("745410836901789749");
if (msg.member.roles.cache.find(r => r.id === '745410836901789749')) {
if(msg.channel.id == 746423099871985755) {
fsn.readJSON("./orders.json").then((orderDB) => {
let ticketID = msg.content.substring(9);
let order = orderDB[ticketID];
// If the order doesn't exist.
if(order === undefined) {
msg.reply("Couldn't find that order. Try again!");
return;
}
//and the rest of the command's code
So you defined employeeRole
, but aren't using it.所以你定义了
employeeRole
,但没有使用它。 Instead of asking if the user has the role employeeRole
, you do something that is not possible in your first if-statement.不是询问用户是否具有角色
employeeRole
,而是在第一个 if 语句中做一些不可能的事情。
if(msg.member.roles.cache.has(employeeRole)) {...}
Change your first if-statement into the code I gave you here and it should be fixed.将您的第一个 if 语句更改为我在这里给您的代码,它应该被修复。 Now you are asking if the user has the
employeeRole
.现在您在询问用户是否拥有
employeeRole
。
PS: You need to add .cache
at your employeeRole
so it has to be PS:你需要在你的
employeeRole
中添加.cache
,所以它必须是
let employeeRole = msg.guild.roles.cache.get("745410836901789749");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.