chrissy
chrissy
DIAdiscord.js - Imagine an app
Created by chrissy on 12/18/2023 in #djs-questions
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 :)
18 replies