即使显示了嵌入,Message.embeds 也未定义

问题描述 投票:0回答:1

这是我当前用来尝试从消息中获取嵌入的代码

const reportMessage = await interaction.channel.messages.fetch({
            limit: 1,
            cache: false,
        });

return console.log(reportMessage.embeds);

现在更重要的是,

reportMessage
确实存在,我可以
console.log
它,它会返回以下内容(出于隐私考虑,所有带有 -- 的地方都会被编辑):

Collection(1) [Map] {
  '--' => Message {
    channelId: '--',
    guildId: '--',
    id: '--',
    createdTimestamp: --,
    type: 0,
    system: false,
    content: '',
    author: ClientUser {
      id: '--',
      bot: true,
      system: false,
      flags: [UserFlagsBitField],
      username: '--',
      globalName: null,
      discriminator: '--',
      avatar: '--',
      banner: null,
      accentColor: null,
      avatarDecoration: null,
      verified: true,
      mfaEnabled: true
    },
    pinned: false,
    tts: false,
    nonce: null,
    embeds: [ [Embed] ],
    components: [],
    attachments: Collection(0) [Map] {},
    stickers: Collection(0) [Map] {},
    position: 0,
    roleSubscriptionData: null,
    resolved: null,
    editedTimestamp: null,
    reactions: ReactionManager { message: [Message] },
    mentions: MessageMentions {
      everyone: false,
      users: Collection(0) [Map] {},
      roles: Collection(0) [Map] {},
      _members: null,
      _channels: null,
      _parsedUsers: null,
      crosspostedChannels: Collection(0) [Map] {},
      repliedUser: null
    },
    webhookId: null,
    groupActivityApplication: null,
    applicationId: null,
    activity: null,
    flags: MessageFlagsBitField { bitfield: 0 },
    reference: null,
    interaction: null
  }
}

但是当我尝试

console.log(reportMessage.embeds)
时,它返回未定义,即使你可以看到有一组嵌入。尝试
console.log(reportMessage.embeds[0])
也不起作用,即使它应该是所有嵌入的数组,而我正在使用第一个。

我期望得到一个嵌入在其中的对象,因为这很明显,我的代码正在尝试做什么。有谁知道如何实际获取一个嵌入其中的对象?

提前感谢您的建议。

javascript discord discord.js
1个回答
0
投票

await interaction.channel.messages.fetch({ limit: 1, cache: false});
返回一个集合。集合中不存在属性
embeds
。如果您想使用集合中的第一条消息,您可以使用
first()
函数返回第一个元素。

const reportMessage = await interaction.channel.messages.fetch({
            limit: 1,
            cache: false,
        });

return console.log(reportMessage.first().embeds);
© www.soinside.com 2019 - 2024. All rights reserved.