【问题标题】:TypeError: Cannot read property 'send' of undefinedTypeError:无法读取未定义的属性“发送”
【发布时间】:2023-03-09 14:48:01
【问题描述】:

我的代码需要帮助。我正在构建不和谐机器人。我不知道我的代码有什么问题,但它给出了

TypeError:无法读取未定义的属性“发送”

if(receivedMessage.content.startsWith("!")) {
    processCommand(receivedMessage)
}

function processCommand(receivedMessage) {
    let fullCommand = receivedMessage.content.substr(1)
    let splitCommand = fullCommand.split(" ")
    let primaryCommand = splitCommand[0]
    let arguments = splitCommand.slice(1)

    if (primaryCommand == "help") {
        helpCommand(arguments, receivedMessage)
    }
}


function helpCommand(arguments, receivedMessage){
    if (arguments.length == 0) {
        receivedMessage.channnel.send("Im not sure what are you looking for.Try 
using `!help [topic]`")
    } else {
        receivedMessage.channel.send("It looks like you need help with " + arguments)
    }
}

【问题讨论】:

  • receivedMessage.channnel 未定义...
  • 你发布了你的登录令牌,你不应该这样做:拥有它的每个人都可以登录到帐户并使用机器人做任何他们想做的事情。我已经从帖子中隐藏了它,但它不是不可见的:您应该从Discord's developers' portal 的机器人页面创建一个新的:bot -> regenerate

标签: javascript discord discord.js


【解决方案1】:

TypeError: Cannot read property 'send' of undefined 告诉你receivedMessage.channnel 是未定义的,然后在行中仔细观察:

  receivedMessage.channnel.send("Im not sure what are you looking for.Try using `!help [topic]`")

您应该注意到您使用的是channnel 而不是channel

【讨论】:

  • 我是编码新手,所以..我的自我意识有点迟钝。非常感谢您的回复
  • 如果答案足够,那么您可以使用它左侧的绿色勾号将您的问题标记为已回答
猜你喜欢
  • 1970-01-01
  • 2020-06-17
  • 2021-11-02
  • 2021-04-12
  • 2021-06-27
  • 2021-04-17
  • 2020-08-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多