【问题标题】:discord.js - How to read data from embeddiscord.js - 如何从嵌入中读取数据
【发布时间】:2022-01-22 04:18:19
【问题描述】:

我正在尝试获取嵌入消息的颜色。该消息有一个嵌入(带颜色),但它仍然在日志中显示false

let messageId = '922497690359716898';

if(messageId.embeds){
    let applicationAuthor = messageId.embeds.color;

    console.log(applicationAuthor)
} else console.log('false');

【问题讨论】:

    标签: javascript node.js discord discord.js bots


    【解决方案1】:

    单个 ID/雪花没有 embeds 属性。您需要先通过此 ID fetch the message 并在解决后检查其 embeds

    如果带有嵌入的消息与带有命令的消息在同一频道,则可以使用:

    let messageId = '922497690359716898';
    try {
      let messageWithEmbed = await msg.channel.messages.fetch(messageId);
      if (messageWithEmbed.embeds?.[0]) {
        let color = messageWithEmbed.embeds[0].color;
        console.log(color);
      } else {
        console.log('no embed found')
      }
    } catch (err) {
      console.log(err);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-11-07
      • 1970-01-01
      • 2021-12-10
      • 2019-01-09
      • 2021-10-14
      • 2019-11-16
      • 2016-12-13
      • 2021-12-13
      • 1970-01-01
      相关资源
      最近更新 更多