【问题标题】:Cannot read property 'api' of undefined in discord.js无法读取 discord.js 中未定义的属性“api”
【发布时间】:2020-12-30 12:01:42
【问题描述】:
client.on("message", (message) => {
  if (message.content === "channelCreate" ) {
    guild.channels.create('test channel', { type: "text" })
    .then(console.log)
    .catch(console.error)
  }
}

当我运行此代码时,我收到此错误消息“TypeError: Cannot read property 'api' of undefined”,老实说,我不知道问题出在哪里。 请帮忙 :( 感谢您的帮助!

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    您很可能使用了 Enmap。您很可能不想这样做,而是使用常规的 Discord 集合。该代码中也没有任何单词“api”——堆栈跟踪会很有帮助。

    【讨论】:

      【解决方案2】:

      我看到了你的错误。在你写的第三行

          guild.channels.create('test channel', { type: "text" })
      

      但公会不够完善,因此会在 discord.js 库中产生问题。

      使用

          message.guild.channels.create('test channel', { type: "text" })
      

      希望能帮到你

      【讨论】:

        猜你喜欢
        • 2022-06-10
        • 2021-06-27
        • 2020-07-20
        • 1970-01-01
        • 2020-12-05
        • 2021-04-14
        • 2021-11-17
        • 1970-01-01
        • 2023-01-14
        相关资源
        最近更新 更多