【问题标题】:How do I check to see if a message collector collected an image? And how do I get that image's Discord URL/proxyURL?如何检查消息收集器是否收集了图像?以及如何获取该图像的 Discord URL/proxyURL?
【发布时间】:2020-08-01 09:38:57
【问题描述】:

我正在使用 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(特别是 proxyURLs),并使用 Discord.js V12 检查收集的消息是否有任何附件。我该怎么做呢?

【问题讨论】:

  • 您能在您的问题中发布console.logging 收集到的消息的输出吗?你能添加一些你的代码吗?
  • @Syntle 好的,完成。
  • 你能显示问题的代码 sn-p 吗?
  • @Syntle 麻烦您了,哈哈。我已经添加了一些我正在谈论的代码。

标签: discord.js


【解决方案1】:

您只需检查邮件是否有附件,然后获取邮件的附件并循环访问它们并将它们发送到频道。

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] })
            })
        }
    })

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

【讨论】:

    猜你喜欢
    • 2021-03-04
    • 2021-04-20
    • 2021-07-05
    • 2012-04-16
    • 2019-12-12
    • 2022-01-21
    • 2019-12-24
    • 1970-01-01
    • 2022-11-17
    相关资源
    最近更新 更多