简体   繁体   English

Discord.js TypeError:无法读取未定义的属性“id”-channel.id

[英]Discord.js TypeError: Cannot read property 'id' of undefined - channel.id

(Working in discord.js Javascript) (在 discord.js Javascript 中工作)

I'm trying to make it so that users can only use commands in my #commands channel.我正在努力使用户只能在我的 #commands 频道中使用命令。 I have this code at the beginning of the command.我在命令的开头有这个代码。

  if (msg === prefix + 'DAILY') {

   if (msg.channel.id === '29124657224757826') {

The daily command worked perfectly before trying to make it only work in one channel.在尝试使其仅在一个频道中工作之前,日常命令工作得很好。 This is the error message I get with the second line included:这是我在第二行中收到的错误消息:

  if (msg.channel.id === '394615572257570826') {
                    ^
TypeError: Cannot read property 'id' of undefined

I believe I just need a channel.id variable, so how would I set it up?我相信我只需要一个 channel.id 变量,那么我该如何设置呢? If that's not the fix, then what is?如果这不是解决方案,那么什么是? Thanks in advance.提前致谢。

like a comment said, the first line in the command handler needs to be msg.content instead of just message.就像评论说的那样,命令处理程序中的第一行需要是 msg.content 而不仅仅是消息。 Another problem is that msg is not defined.另一个问题是 msg 没有定义。 I bet it's because your command handler is not msg but is something else like message.我敢打赌,这是因为您的命令处理程序不是 msg,而是其他类似消息的东西。 Based off another similar problem that is from this基于另一个类似的问题,来自this

what you would want to do is to find the channel using msg.guild.channels.find().您想要做的是使用 msg.guild.channels.find() 找到频道。 The question I have is what are you trying to do after line 2 where you are looking for the channel to match the id which may give you a better understanding我的问题是您在第 2 行之后要做什么,在那里您正在寻找与 id 匹配的频道,这可能会让您更好地理解

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM