Javascript TypeError:无法读取未定义的discord js的属性“first”

Javascript TypeError:无法读取未定义的discord js的属性“first”,javascript,discord,discord.js,Javascript,Discord,Discord.js,我知道我在这方面不是最棒的,我还在学习,但谁能帮我解决我的错误,我知道这与我的let role=有关,与“=”符号有关,我只是不确定该改什么 如果message.member.hasPermission'MANAGE_CHANNELS'返回message.replyEmbed3 如果args[0]返回消息。replyEmbed2 如果message.notices.channels.first return message.replyEmbed1 让role=message.guild.role

我知道我在这方面不是最棒的,我还在学习,但谁能帮我解决我的错误,我知道这与我的let role=有关,与“=”符号有关,我只是不确定该改什么

如果message.member.hasPermission'MANAGE_CHANNELS'返回message.replyEmbed3 如果args[0]返回消息。replyEmbed2 如果message.notices.channels.first return message.replyEmbed1 让role=message.guild.roles.cache.findr=>r.name=args[1]//const role=message.indications.roles.first 如果角色返回message.replyembe4; 当前错误为

TypeError: Cannot read property 'first' of undefined
我在跟踪,但仍然不知道该怎么办

非常感谢您的帮助,祝您度过愉快的一天

编辑1

在我的index.js中,我有这个

-

client.on'message',message=>{ if!message.content.startsWithprefix | | message.author.bot返回; 设args=message.content.substringprefix.length.split; const命令=args.shift.toLowerCase; 如果命令==='lock'{ client.commands.get'lock'.executemessage,args }如果命令==='unlock'{ client.commands.get'unlock'.executemessage,args } } 编辑2

此行后停止打印

 if (channel.name.startsWith('I believe your mistake might have been attempting to find the first mentioned user in the channel. You would need to have used 
.fetch()
for this. Make sure you respect your promise if you're using async!

If this isn't what you want and you simply want to find the first user that is mentioned in the message that the command is run on, you would need to use:

        if (!message.mentions.users.first()) return message.reply(Embed1)

如果channel.name.startsWith',我相信您的错误可能是试图在频道中找到第一个提到的用户。你应该用过。拿着这个。如果使用异步,请确保遵守您的承诺

如果这不是您想要的,并且您只是想找到运行该命令的消息中提到的第一个用户,那么您需要使用:

如果message.notices.users.first return message.replyEmbed1
所以从我在discord文档中读到的

我在你的代码中看到了:

如果在不同的通道中没有提及,则提及可能没有通道属性集。因此,您可能需要检查:

if (message.mentions.channels || !message.mentions.channels.first()) return message.reply(Embed1)
此外,您使用的find也很奇怪:

let role = message.guild.roles.cache.find(r => r.name = args[1]);
filter方法中的此语句将始终将缓存的名称设置为args[1],并返回值。如果args[1]为true,则它将返回第一个缓存对象。 你需要的是在这个地方进行比较

let role = message.guild.roles.cache.find(r => r.name == args[1]); // does not check type
or
let role = message.guild.roles.cache.find(r => r.name === args[1]); // checks type
编辑2:

您可能还需要检查访问channel.first道具的方式。channel.first是一种方法。如果您希望此方法的结果是舒尔调用它

并用then方法正确处理承诺。因为setName会给你一个承诺,你需要接受它!


message.indications.channels.first.setName`这是客户端中的代码。在'message',message=>{block?在my index.js中,这是在模块导出中={block,在我的index.js中是这样的:将其更改为上面的,因为它没有格式化,请参阅原始问题这是导致错误消息的原因。references.channels。首先,尝试控制台记录对象的每个部分,以查看其未定义的位置。我认为是references对象未定义。好的,我现在就尝试。好的,找到了,它在这个lin之后停止打印e参见上文哦,我应该添加一个获取消息的小示例const messageFetch=await message.channel.messages.fetchi!请查看上面的注释,感谢您的帮助!没问题!如果这确实解决了问题,请确保将其标记为answeredIt抛出了一些错误,因为我们在函数中使用await,它不会拾取异步'await channel.updateOverwriterole,{^^^^^^^ SyntaxError:await仅在async函数中有效`我还使用VSCode格式的文档pluginJea。这是真的。如果你不知道async await的作用:它使你能够将异步调用作为一行同步调用来处理:如果你不需要等待此结果,请将其保留或用异步方法包装。对不起,我是j的新手s、 我怎么能把它包装成一个异步函数呢?没问题。但是我想我现在知道你想做什么了;我上面的代码省去了等待。