Discord.js v13 Sending a File Attachment via URL

Discord.js released v13 and I'm trying to update my little homebrew discordbot.

I've come across an issue where I can no longer send an attached file (png) via a web URL.

Discord.js v12

var testchart = ` message.channel.send("Last updated " + updatedAt.fromNow(), { files: [{ attachment: testchart, name: 'file.png' }] 

No errors to the console are made (other than a depreciation warning): No errors to the console are made

And the bot does not return an image:

no image

I've tried:

message.channel.send("Last updated " + updatedAt.fromNow(), { files: [testchart] 

and

message.channel.send("Last updated " + updatedAt.fromNow(), { files: Array.from(testchart) }); 

And finally

message.channel.send({ files: [testchart], content: `Last updated ${updatedAt.fromNow()}` }); 

Which gives me this AWFUL output: enter image description here

Thanks for the help!

Discord.js's guide for updates:

Only other issue I was able to find on the matter: Discord.js V13 sending message attachments

1

2 Answers

Found the issue, it has to do with the testchart2.php part of the URL ()

Was able to get it sent by using:

message.channel.send({ files: [{ attachment: testchart, name: 'chart.png' }], content:`Last updated ${updatedAt.fromNow()}`, }); 

Basically, just take the content part of the v12 and move it to it's own area. Worked like a charm.

Your first attempt was close, but not exactly correct. You just have to merge those together (sending messages only takes 1 argument now) and you will get a png file (because you specified the file name), along with the content:

var testchart = ` message.channel.send({ content: "Last updated " + updatedAt.fromNow(), files: [{ attachment: testchart, name: 'file.png' }] }) 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like