Unable to add attachments in InteractionType.APPLICATION_COMMAND

Hi there! I am new to creating Discord bots and recently followed the https://discord.com/developers/docs/getting-started tutorial, which uses discordJS with an interactions endpoint URL where Discord will send HTTP Requests and you return something of the form res.send(...). I am trying to do the following: respond with a local video file attached when a user does the /get-video command. I've looked through all of the attachments documentation but have not been able to find an answer. I do NOT want this in an embed, just want it to be a good old attachment Some more details - The video file is saved in the same place as my app.js where the code below lives, so the file path is "video.mp4" - My JS type is module, since I adapted it from the getting started tutorial, but I'm open to suggestions on refactoring my code to make it easier - Right now, the bot will respond to my "/get-video" command, but it doesn't include the embed Here is my code so far which does respond but fails to add an attachment if (type === InteractionType.APPLICATION_COMMAND) { const { name } = data; // The command I'm working on if (name === 'get-video') { const userId = req.body.member.user.id; const videoPath = "video.mp4"; const file = new AttachmentBuilder(videoPath); return res.send({ type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, data: { content: video for <@${userId}> and ${file} and path ${videoPath}, flags: InteractionResponseFlags.EPHEMERAL, components: [ { type: MessageComponentTypes.ACTION_ROW, components: [ { type: MessageComponentTypes.BUTTON, // Append the ID to use later on custom_id: acceptbutton${req.body.id}, label: 'my button', style: ButtonStyleTypes.PRIMARY, }, ], }, ], files: [file] }, }); As you can see, I have put the attachment under "files", but nothing shows up! Would sincerely appreciate any help :)
10 Replies
d.js toolkit
d.js toolkit13mo 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
chrissy
chrissyOP13mo ago
- [email protected] - node -v v18.12.0
kin.ts
kin.ts13mo ago
looks like you're using axios or something similar, but, if you want to upload files when using an endpoint, you need to append a form data to your body request
chrissy
chrissyOP13mo ago
Oh interesting, I did import { AttachmentBuilder } from 'discord.js' in hopes of being able to use it, but is it incompatible? I see, is this generally a less straightforward way of doing it than discord.js? Why wouldn't the discord tutorial use discord.js 🤔 Ohh okay got it, so would you rec that I scrap what they did in the tutorial and completely build on top of discord.js instead?
d.js docs
d.js docs13mo ago
Suggestion for @chrissy:discord Reference: API Reference - Uploading Files read more
chrissy
chrissyOP13mo ago
Thanks for sharing the resource! I was kind of confused looking at this, does this mean I add an attachments key and put the file name there? Oh I see, I want to make a bot that eventually calls an endpoint I have (makes a HTTP request), would Djs not be suitable for that?
kin.ts
kin.ts13mo ago
right
chrissy
chrissyOP13mo ago
I'm not really clear on what the differences are? Gateway vs http interactions? Ty for all the clarifications btw
kin.ts
kin.ts13mo ago
Gateway is used to receive event like messageCreate, guildCreate Http interactions used for interacting with interactions via https request and response
chrissy
chrissyOP13mo ago
Could you clarify how that might look as just a video attachment (not embeds)? Would that go in the place where I have files rn return res.send({ type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, data: { content: video for <@${userId}> and ${file} and path ${videoPath}, flags: InteractionResponseFlags.EPHEMERAL, components: [ { type: MessageComponentTypes.ACTION_ROW, components: [ { type: MessageComponentTypes.BUTTON, // Append the game ID to use later on custom_id: acceptbutton${req.body.id}, label: 'pls accept', style: ButtonStyleTypes.PRIMARY, }, ], }, ], files: [file] }, }); Thanks, that's a really good explanation! I think I only need HTTP interactions since my bot is intended to only respond to specific commands, but I really appreciate the time you took to explain it to me You too @Kin as unknown; thanks for taking the time to look at my case!
Want results from more Discord servers?
Add your server