【问题标题】:Connect read 'send' of undefined连接读取未定义的“发送”
【发布时间】:2020-11-02 03:43:42
【问题描述】:

我使用 discord.js@12.2.0


代码: 让 reviewChannel = client.channels.cache.get(reviewChannelID);

reviewChannel.send(嵌入)


错误: A:\GhostBot\src\cmds\utility\review.js:62 reviewChannel.send(嵌入) ^

TypeError:无法读取未定义的属性“发送” 在声明。 (A:\GhostBot\src\cmds\utility\review.js:62:27) 在 Statement.replacement (A:\GhostBot\node_modules\sqlite3\lib\trace.js:25:27)


【问题讨论】:

  • 这个错误意味着它找不到频道。也许您使用了不正确的 ID,或者机器人不在正确的服务器中。
  • 你的密码是什么?

标签: discord.js message


【解决方案1】:

假设client 是一个Client 对象,client.channels.cache 返回一个ChannelManagerCollection 频道,其中它的键是Snowflakes。如果您使用无效密钥在Collection 上调用.get(),则它会根据文档返回undefined。在您的情况下,您的reviewChannel 变量确实是undefined 而不是Channel,因为您的错误表明它不能.send() 关闭undefined

因此,即使您没有包含定义reviewChannelID 的代码部分,该变量也可能有问题。 Snowflake 的文档中列出的类型是 string。你可能写了这样的东西:

let reviewChannelID = 123456789012345678; //number type

代替:

let reviewChannelID = "123456789012345678"; //string type

所以如果我没记错的话,添加一些引号将reviewChannelID 定义为字符串应该是一个简单的解决方法。

【讨论】:

    猜你喜欢
    • 2022-01-24
    • 1970-01-01
    • 2022-01-10
    • 2020-12-19
    • 2023-03-09
    • 2021-04-16
    • 2020-06-05
    相关资源
    最近更新 更多