I am trying to collect an image with the awaitMessages function but I can't seem to be able to get an image URL as I would normally get from a normal message.
Normally I am able to get the URL from a message by message.attachments.toJSON()[0]["url"]
but now that doesn't work.
When I convert the collected messages to JSON by using collectedMessages.toJSON()
it looks like this:
[
{
channelID: '809335881680289832',
deleted: false,
id: '840910718911905802',
type: 'DEFAULT',
system: false,
content: '',
authorID: '539789850983923712',
pinned: false,
tts: false,
nonce: null,
embeds: [],
attachments: [ '840910718810456084' ],
createdTimestamp: 1620559138754,
editedTimestamp: 0,
webhookID: null,
activity: null,
flags: 0,
reference: null,
guildID: '809079026224201800',
cleanContent: ''
}
]
and when i directly log the collected messages it looks like this:
Collection [Map] {
'840912580015947837' => Message {
channel: TextChannel {
type: 'text',
deleted: false,
id: '809335881680289832',
name: 'premium-verification',
rawPosition: 1,
parentID: '809079026224201801',
permissionOverwrites: [Collection [Map]],
topic: null,
lastMessageID: '840912580015947837',
rateLimitPerUser: 0,
lastPinTimestamp: null,
guild: [Guild],
messages: [MessageManager],
nsfw: false,
_typing: Map {}
},
deleted: false,
id: '840912580015947837',
type: 'DEFAULT',
system: false,
content: '',
author: User {
id: '539789850983923712',
system: null,
locale: null,
flags: [UserFlags],
username: 'Mr.Astatine',
bot: false,
discriminator: '2270',
avatar: 'f5cec89cb417760e0ff6aa82fb03fddf',
lastMessageID: '840912580015947837',
lastMessageChannelID: '809335881680289832'
},
pinned: false,
tts: false,
nonce: null,
embeds: [],
attachments: Collection [Map] { '840912579949625354' => [MessageAttachment] },
createdTimestamp: 1620559582476,
editedTimestamp: 0,
reactions: ReactionManager {
cacheType: [class Collection extends Collection],
cache: Collection [Map] {},
message: [Circular]
},
mentions: MessageMentions {
everyone: false,
users: Collection [Map] {},
roles: Collection [Map] {},
_members: Collection [Map] {},
_channels: null,
crosspostedChannels: Collection [Map] {}
},
webhookID: null,
application: null,
activity: null,
_edits: [],
flags: MessageFlags { bitfield: 0 },
reference: null
}
}
Please help me in getting the URL of the attachment from these types of collected messages.
You need to use collectedMessages.first().attachments.first().url
https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=attachments https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=first https://discord.js.org/#/docs/main/stable/class/MessageAttachment?scrollTo=url
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.