【问题标题】:Get specific message from specific channel从特定频道获取特定消息
【发布时间】:2020-06-29 15:30:04
【问题描述】:

目的:我正试图让我的机器人检查来自特定消息的反应。

我读过这篇文章:Get Message By ID: Discord.js 但它根本没有帮助。

我在网上搜索了如何正确使用.fetchMessage。但遗憾的是没有找到任何结果。

这是我的代码:

client.channels.get('CHANNEL ID').fetchMessage('MESSAGE ID').then(async msg => { *CODE HERE* });

这是我得到的错误:

TypeError: client.channels.get is not a function

我确实意识到 client.channels.get is not a function 我应该在函数中使用它,但我不知道如何使用。

Discord.js version: 12.0.2

Node.js verison: 12.13

【问题讨论】:

标签: bots discord discord.js


【解决方案1】:

这个答案是针对 v11 的,在 v12 中它已更改为:

client.channels.cache.get(chid).messages.cache.fetch(mesid)

但是,重要的是要注意 client.channels.cache 可能包含非文本通道,如果您要检索的 ID 知道是 TextChannel 类型,您会很好,但如果正在以编程方式检索 ID,您需要检查以确保它是 TextChannel 的实例。

【讨论】:

  • 我收到此错误:Cannot read property 'message' of undefined。我正在使用文本频道的 ID 顺便说一句
  • 抱歉,打错了,应该是复数messages
  • 它仍然认为它未定义:(
  • 在这种情况下,听起来好像没有找到频道,所以 channels.cache.get() 返回未定义。你确定你有一个正确的 ID 并且你的机器人可以看到频道(权限方面)吗?
  • 我在client.on(ready) 函数中尝试过console.log(client.channels.cache.get('689781285148950545').name);。它记录正确。
【解决方案2】:

在 v12 中它已更改并使用管理器并将此命令添加到我的机器人并修复它。

let channelMessage = client.channels.cache.get(channel_id) // Grab the channel
channelMessage.messages.fetch(message_id).then(messageFeteched => messageFeteched.delete({timeout: 5000})); // Delete the message after 5 seconds

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 1970-01-01
    • 2021-07-30
    • 2020-07-02
    相关资源
    最近更新 更多