【问题标题】:I am trying to send a message to a specific channel using ID, but it outputs Cannot read property 'send' of undefined我正在尝试使用 ID 向特定频道发送消息,但它输出无法读取未定义的属性“发送”
【发布时间】:2019-08-27 23:53:22
【问题描述】:

我有一个建议命令,我想发送到我服务器中的特定频道。

if (!args) return message.channel.send("Please input a suggestion"); {
client.channels.get("563804889268879390").send({embed: {
color: 0x333333,
author: {
 name: "New suggestion!",
},
fields: [{
 name: "User",
 value: ${message.author.user}
},
{
 name: "Suggestion",
 value: args
},
]}})}    

我将消息定义为client.on("message", async message => {。 即使我键入没有任何参数的命令,它也不会响应错误消息。当我尝试使用它时,它输出的只是(node:17876) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined。这些参数在我的其他命令上工作正常,所以我不知道问题可能是什么。

【问题讨论】:

  • 能否告诉我们您如何定义消息?
  • 我已将帖子更改为适合,谢谢
  • 在第一行的末尾有一个不适合的左括号。这是为什么呢?也许这导致了错误

标签: javascript node.js bots discord discord.js


【解决方案1】:

Cannot read property 'send' of undefined很可能表示client.channels.get("563804889268879390")未定义,表示频道ID错误或Bot不在频道所在的公会中。

确保 ID 有效!

【讨论】:

  • 谢谢!频道有权限,我忘了我不允许机器人发送消息。
猜你喜欢
  • 2020-09-07
  • 2021-03-25
  • 2021-10-23
  • 2021-05-07
  • 2022-01-08
  • 2022-01-10
  • 1970-01-01
  • 2020-07-02
相关资源
最近更新 更多