【问题标题】:TypeError: Cannot read property 'channels' of undefined DISCORDTypeError:无法读取未定义 DISCORD 的属性“通道”
【发布时间】:2021-01-01 02:59:42
【问题描述】:

运行此代码时出现此错误,但我无法弄清楚它为什么不起作用..

TypeError: Cannot read property 'channels' of undefined
    at Request._callback (/Users/carlohera/Desktop/test.js:13:33)

【问题讨论】:

  • 您使用的是什么版本的 discord.js?看来 v12 和 v11 的功能有冲突
  • 12.3.1,请告诉我它需要如何。

标签: javascript api discord bots


【解决方案1】:

您的变量 guild 似乎未设置并且为空/未定义。 也许您应该检查您的 client.guilds.cache.get 是否具有正确的语法以及参数是否正确。由于公会未定义,您的 guild.channels.get 会导致错误。

【讨论】:

    【解决方案2】:

    公会和频道的 ID 应该是 Strings,而不是 Numbers

    let guild = client.guilds.cache.get('700967388379742318');
    let channel = guild.channels.cache.get('754993174954508308'); // also, make sure to use `cache.get`
    

    【讨论】:

    • TypeError: Cannot read property 'channels' of undefined ..... 同样的事情
    • 你使用的是什么版本的 discord.js?
    • 最新的“npm install discord.js” - 12.3.1
    • 那么你的ID就是无效的。
    • 你能再解释一下吗?
    猜你喜欢
    • 2021-10-20
    • 2021-08-29
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 2021-03-31
    • 1970-01-01
    • 2019-05-09
    相关资源
    最近更新 更多