如何检查邮件收集器是否收集了图像?以及如何获取该图像的Discord URL / proxyURL?

时间:2020-04-18 20:58:07

标签: discord.js

我正在Discord.js V12中进行编码,我想知道如何在awaitMessages()消息收集器中获取已收集消息的附件。

collected(其中仅包含图像的已收集消息)的输出是这样的:

Collection [Map] {
  '701180292689297429' => Message {
    channel: DMChannel {
      type: 'dm',
      deleted: false,
      id: '700086368558121047',
      recipient: [User],
      lastMessageID: '701180292689297429',
      lastPinTimestamp: null,
      messages: [MessageManager],
      _typing: Map {}
    },
    deleted: false,
    id: '701180292689297429',
    type: 'DEFAULT',
    content: '',
    author: User {
      id: '252268366079852584',
      bot: false,
      username: 'EBB',
      discriminator: '5732',
      avatar: 'd60958dccad619bd70225373ed312bbf',
      flags: [UserFlags],
      lastMessageID: '701180292689297429',
      lastMessageChannelID: '700086368558121047'
    },
    pinned: false,
    tts: false,
    nonce: undefined,
    system: false,
    embeds: [],
    attachments: Collection [Map] { '701180291405971506' => [MessageAttachment] },
    createdTimestamp: 1587244809077,
    editedTimestamp: null,
    reactions: ReactionManager {
      cacheType: [Function: Collection],
      cache: Collection [Map] {},
      message: [Circular]
    },
    mentions: MessageMentions {
      everyone: false,
      users: Collection [Map] {},
      roles: Collection [Map] {},
      _members: null,
      _channels: null,
      crosspostedChannels: Collection [Map] {}
    },
    webhookID: null,
    application: null,
    activity: null,
    _edits: [],
    flags: MessageFlags { bitfield: 0 },
    reference: null
  }
}

这是我指的代码:

dmc.awaitMessages(resp => resp.author.id === message.author.id, {
                max: 1,
                time: 60000,
                errors: ['time']
              }) 
              .then(collectedfive => {
                    let imageOrNo = collectedfive.first().content
                    console.log(imageOrNo)
                    message.channel.send(<I WOULD SEND THE IMAGE BACK TO THEM, BUT I DON'T KNOW HOW TO, AND I ALSO WOULD CHECK TO SEE IF THERE IS AN ATTACHED IMAGE TO THE MESSAGE)
                  })
})

我想获取附件及其URL(特别是proxyURL),并使用Discord.js V12来检查收集的邮件中是否有任何附件。我将如何去做?

1 个答案:

答案 0 :(得分:0)

您只需检查邮件中是否包含附件,然后获取邮件的附件并遍历它们,然后将其发送到频道。

dmc.awaitMessages(resp => resp.author.id === message.author.id, {
    max: 1,
    time: 60000,
    errors: ['time']
})
.then(collectedfive => {
        if (collectedfive.first().attachments.array().length) {
            collectedfive.first().attachments.forEach((attachment) => {
                message.channel.send({ files: [attachment] })
            })
        }
    })

您还可以通过在上面的proxyURL循环中使用attachment.proxyURL来获取附件的forEach()属性