Sending Images with djs/rest

My issue is that the promise dont get resolved of the rest#post() neither the followup works in Discord and I dont see what the issue is. My rest function:
static async sendFollowUp(interaction, data, files) {
const rest = GatewayManager.getRest();

return rest
.post(Routes.webhook(interaction.application_id ?? "927598798019108894", interaction.token), {
body: data,
files: files ?? [],
});
}
static async sendFollowUp(interaction, data, files) {
const rest = GatewayManager.getRest();

return rest
.post(Routes.webhook(interaction.application_id ?? "927598798019108894", interaction.token), {
body: data,
files: files ?? [],
});
}
getRest is a valid rest instance My code that dont work
return GatewayManager.sendFollowUp(interaction, {
embeds: [
{
image: {
url: "attachment://image.png"
},
color: 0x146533,
}
],
}, [{
data: image,
name: 'image.png'
}]);
return GatewayManager.sendFollowUp(interaction, {
embeds: [
{
image: {
url: "attachment://image.png"
},
color: 0x146533,
}
],
}, [{
data: image,
name: 'image.png'
}]);
Image is a valid buffer generated with @napi-rs/canvas Any ideas?
11 Replies
d.js toolkit
d.js toolkit12mo 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! - Marked as resolved by OP
sean
seanOP12mo ago
The reason is its a http only bot I actually would like to stick to my own and only use /rest or are there any benifits of the core/http-only ? (since its not a new bot its already a exisitng bot) but about the form thing why does rest post have "files" as typing if I need to do it with formData? I expected that it does that by its own thats what I tought too bcs of the "files" property its a buffer its a buffer generated from @napi-rs/canvas with
const image = await new CanvasHelper(
gameData.firstEntry.name,
gameData.firstEntry.value,
gameData.secondEntry.name
).generateImage();
const image = await new CanvasHelper(
gameData.firstEntry.name,
gameData.firstEntry.value,
gameData.secondEntry.name
).generateImage();
and generateImage returns
const img = canvas.toBuffer("image/png");
Canvas.clearAllCache();
return img;
const img = canvas.toBuffer("image/png");
Canvas.clearAllCache();
return img;
logged also the event 'response' from rest and it also dont get triggered if you mean with auth token the bot token then yes since when is both of these options needed I dont do that at the other 4 bots using the same function 💀 I dont get it I see so would it be like this?
.post(Routes.webhook(interaction.application_id, interaction.token), {
body: data,
files: files ?? [],
query: 'wait=true&auth=false'
});
.post(Routes.webhook(interaction.application_id, interaction.token), {
body: data,
files: files ?? [],
query: 'wait=true&auth=false'
});
so wait can be removed? since I dont need the msg ahhh Okay I did that now, sadly it still at all dont work I also dont get why it not just drop a error it just gets stuck thats what I thought too but other cmds works fine yes same route, but let me add that no log req.body its 100% something wrong with the attachments but I just dont know what (since when I comment files: out it response)
sean
seanOP12mo ago
No description
sean
seanOP12mo ago
(thats files) Just added that xD everything other is still the same sure
sean
seanOP12mo ago
just logged the whole route to be sure and its what I expect
No description
sean
seanOP12mo ago
I just thought let me add .catch() and now I have a error
No description
sean
seanOP12mo ago
🤔
sean
seanOP12mo ago
No description
sean
seanOP12mo ago
I would now add a console log at the resolveRequest but this minified dist is annoying yeah would just do it for debugging tho I cant really do much with the error since I defined name yeah still same xd
sean
seanOP12mo ago
its this pos of the code that currently errors isnt it? https://github.com/discordjs/discord.js/blob/main/packages/rest/src/lib/REST.ts#L359
GitHub
discord.js/packages/rest/src/lib/REST.ts at main · discordjs/discor...
A powerful JavaScript library for interacting with the Discord API - discordjs/discord.js
sean
seanOP12mo ago
bcs if yes then I really dont know whats wrong <a:cry_cat:777955315291127829> 18.12.0 omg.... It works now check here the version of rest I installed... Yep had the same reaction idk why but my npm likes to install old versions when I dont add @latest at the end its from a old part of the bot I use collections from djs and was to lazy to require /collections xD but still thanks for your help tho
Want results from more Discord servers?
Add your server