【问题标题】:How can I detect embeds in a message?如何检测消息中的嵌入?
【发布时间】:2019-05-15 06:11:40
【问题描述】:

我试图让我的机器人读取其他机器人的丰富嵌入,但我什至找不到从哪里开始做。我已阅读文档,但我仍然不知道该怎么做...
使用if(message.content.includes(x)) 不起作用,我该怎么办?

【问题讨论】:

  • 调试是你的朋友。 console.log 所有的东西,直到你找到你要找的东西。

标签: javascript embed discord.js


【解决方案1】:

收到消息后,其嵌入存储在<Message>.embeds:为了读取它们,您可以遍历该数组并查看每个嵌入的属性:

client.on('message', message => {
  for (let embed of message.embeds) { // these are some of the properties
    console.log(`
    Title: ${embed.title}
    Author: ${embed.author}
    Description: ${embed.description}
    `);
    for (let field of embed.field) {
      console.log(`
      Field title: ${field.name}
      Field value: ${field.value}
      `);
    }
  }
});

您可以在 MessageEmbedMessageEmbedField 的文档中找到这些属性。

【讨论】:

  • 谢谢!您的解释非常有效,我的机器人正在运行并发现恶意嵌入!
  • 很高兴听到这个消息:)
猜你喜欢
  • 1970-01-01
  • 2021-02-21
  • 2022-01-17
  • 1970-01-01
  • 2020-03-06
  • 2017-01-17
  • 2020-09-05
  • 2022-08-04
相关资源
最近更新 更多