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 = `http://jegin.net/testchart2.php?sysid=268.png`;
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):
And the bot does not return an 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:
Thanks for the help!
Discord.js's guide for updates: https://discordjs.guide/additional-info/changes-in-v13.html#sending-messages-embeds-files-etc
Only other issue I was able to find on the matter: Discord.js V13 sending message attachments
CodePudding user response:
Found the issue, it has to do with the testchart2.php part of the URL (http://jegin.net/testchart2.php?sysid=268.png)
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.
CodePudding user response:
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 = `http://jegin.net/testchart2.php?sysid=268.png`;
message.channel.send({
content: "Last updated " updatedAt.fromNow(),
files: [{
attachment: testchart,
name: 'file.png'
}]
})