-
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 When I convert the collected messages to JSON by using
and when i directly log the collected messages it looks like this:
Please help me in getting the URL of the attachment from these types of collected messages. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
That's because You should use Or alternatively, in older syntax (if you don't use Node.js v14): const attachment = message.attachments.first();
const url = attachment ? attachment.url : null; There's also the possibility to do: const [attachments] = message.attachments.values();
const url = attachment ? attachment.url : null; |
Beta Was this translation helpful? Give feedback.
That's because
Collection#toJSON()
callstoJSON()
to all of its values, which may not have the same information as not everything can be serialized, that includesMessageAttachment#toJSON()
.You should use
message
.
attachments
.
first()
?.
url
.Or alternatively, in older syntax (if you don't use Node.js v14):
There's also the possibility to do: