#Unable to add attachments in InteractionType.APPLICATION_COMMAND

27 messages · Page 1 of 1 (latest)

coral cypress
#

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: `accept_button_${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 :)

vivid etherBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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
coral cypress
night quartz
#

That tutorial does not use discord.js at all. Neither is your code you showed there

swift epoch
coral cypress
coral cypress
#

Why wouldn't the discord tutorial use discord.js 🤔

night quartz
#

Yes, you’d need to use that with discord.js methods to work

#

Because it doesn’t use any library but raw requests

#

To show how the api works (and because djs is not a library for http interactions in the first place)

coral cypress
night quartz
#

That depends on what you intend to build

#

Djs is a gateway bot library, you won‘t make http interactions only bots with it

dense patrolBOT
#

Suggestion for @coral cypress:
discord Reference: API Reference - Uploading Files
read more

coral cypress
coral cypress
night quartz
#

You need to decide: use djs and ask here; or not use djs and ask somewhere else (ddevs in #useful-servers for example)

night quartz
coral cypress
#

Ty for all the clarifications btw

swift epoch
coral cypress
# swift epoch right

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: accept_button_${req.body.id}, label: 'pls accept', style: ButtonStyleTypes.PRIMARY, }, ], }, ], files: [file] }, });

night quartz
#

(Technically that explanation is wrong, because you can still do some things directly via REST, but it won‘t show as an online user)

coral cypress