Skip to content
\n

You can then use this function to download the attachment. I liked the idea, so I added it directly in the API 5a5063a

\n

Final code

\n
;(async () => {\n    api.update_guildId_and_channelId_withCurrentlyVisible()\n    let channelId = api.getConfig().channelId\n\n    const messages = await api.getMessages(channelId)\n    console.log(messages)\n    \n    console.log('List of attachments in the latest message', messages[0].attachments)\n    console.log('URL of the first attachment in the latest message', messages[0].attachments[0].url)\n    api.downloadFileByUrl(messages[0].attachments[0].url, messages[0].attachments[0].filename)\n})()
","upvoteCount":1,"url":"https://github.com/rigwild/discord-self-bot-console/discussions/66#discussioncomment-8191329"}}}

How to download attachments (file, image) from a message? #66

Answered by rigwild
lschaupp asked this question in Q&A
Discussion options

You must be logged in to vote

You can read the attachments inside a message at the key attachments

See in the Discord documentation, the Message data model

Example image attachment

{
    "id": "1198292395519909948",
    "filename": "2024-01-07_23-28-19.png",
    "size": 10358,
    "url": "https://cdn.discordapp.com/attachments/826934811846377545/1198292395519909948/2024-01-07_23-28-19.png?ex=65be5fc2&is=65abeac2&hm=b4a6d3c271e28969e5ae836c776f3597ceda7b326c24949f30b43a29a7791cde&",
    "proxy_url": "https://media.discordapp.net/attachments/826934811846377545/1198292395519909948/2024-01-07_23-28-19.png?ex=65be5fc2&is=65abeac2&hm=b4a6d3c271e28969e5ae836c776f3597ceda7b326c24949f30b43a29a7791cde&",
    "width": 144,
    "…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rigwild
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #63 on January 20, 2024 15:49.