【问题标题】:Cannot read property 'find' of undefined Discord.js无法读取未定义 Discord.js 的属性“查找”
【发布时间】:2020-10-04 04:55:27
【问题描述】:

我正在尝试让 discord.js 机器人从一个频道中删除一条被审查的消息并将其登录到管理员频道,这是我的代码:

 msg.channel.send(exampleEmbed1);
 msg.guilds.find("721079782833520651").send("Test")
It says this error:

 TypeError: Cannot read property 'find' of undefined
 at Client.<anonymous> (/Users/DShirriff/rebelbot/rebel.js:35:16)
 at Client.emit (events.js:323:22)
 at MessageCreateAction.handle (/Users/DShirriff/rebelbot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
 at Object.module.exports [as MESSAGE_CREATE] (/Users/DShirriff/rebelbot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32) etc.

请有人帮忙 :) 我对 discord.js 很陌生,我在其他人的问题中找不到答案

【问题讨论】:

    标签: bots discord discord.js


    【解决方案1】:

    使用那个 (v12)

    let channelID = "channeid";
    client.channels.cache.get(channelID).send("Your Text")
    
    // replace channelid to your channel id
    

    简单,不是吗?

    【讨论】:

      【解决方案2】:

      msg.guilds 不存在。

      你的意思是msg.guild?如果你想从那个公会获得一个频道,你需要使用msg.guild.channels

      取决于您使用的版本:

      v11:

      const channel = msg.guild.channels.get("channel_id");
      

      v12:

      const channel = msg.guild.channels.cache.get("channel_id");
      

      【讨论】:

      • msg.guilds.cache.find("721079782833520651").send("Test") 这个?它不能以这种方式工作。我要一起删除 .find 吗?
      • .find使用回调找到它,如果你想通过id获取集合的元素,使用.get("72107...."),更新我的答案
      • 它说 msg.guilds.cache.get("721079782833520651").send("Test") 的“无法读取未定义的属性缓存”
      • 等等,你是想获得频道还是公会? .send() 看起来像是第一个选项,如果您想要当前公会的频道,则需要使用 msg.guild.channels
      • 这篇文章有一些矛盾,所以我很困惑,但我想我知道你现在要做什么了。更新了我的答案。
      猜你喜欢
      • 2022-06-10
      • 2021-06-27
      • 2020-07-20
      • 1970-01-01
      • 2020-12-05
      • 2021-04-14
      • 2021-12-21
      • 2021-11-17
      • 1970-01-01
      相关资源
      最近更新 更多