Attach files with @discordjs/rest

How do I attach files and send POST it to channel message endpoint properly?
4 Replies
d.js toolkit
d.js toolkit16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
yuki
yukiOP16mo ago
it says no attachment found
yuki
yukiOP16mo ago
const attachment = ctx.message.attachments.at(0)!;
const img = await got.get(attachment.proxy_url).buffer();

const cache = cast<APIMessage>(await this.container.client.rest.post(Routes.channelMessages(), {
body: {
attachments: [
{
id: 0,
filename: attachment.filename
}
]
},
files: [
{
data: img,
name: attachment.filename,
contentType: attachment.content_type,
key: "0"
}
]
}));
const attachment = ctx.message.attachments.at(0)!;
const img = await got.get(attachment.proxy_url).buffer();

const cache = cast<APIMessage>(await this.container.client.rest.post(Routes.channelMessages(), {
body: {
attachments: [
{
id: 0,
filename: attachment.filename
}
]
},
files: [
{
data: img,
name: attachment.filename,
contentType: attachment.content_type,
key: "0"
}
]
}));
any idea? attachment variable is raw attachment from discord yeah ik, that would be diff case, i removed it when i attach the code here alright ill try that fixed the problem, ty
Want results from more Discord servers?
Add your server