Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
SlashCommandBuilder option to add file attachment (addAttachmentOption). Is there a way to get the image sent?

I'm following the discord guide (https://discordjs.guide/#before-you-begin) for making a bot, and I was able to set everything up fine. But I tried to make a slash command where the user attaches an image to the chat input box and the image is sent by the bot in the specified channel. The thing is, I can't find a way to get the image from the input, here how it works:

const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('diario')
        .setDescription('Escreve uma notícia!')
                .setDefaultPermission(false)
        .addStringOption(option => option.setName('titulo').setDescription('Escreva seu título!')
        .setRequired(true))
        .addStringOption(option => option.setName('descrição').setDescription('Descreva brevemente.')
        .setRequired(true))
        .addAttachmentOption(option => option.setName('imagem').setDescription("Anexe uma imagem ilustrativa")
        .setRequired(true)),
    async execute(interaction) {
        const action = await interaction;
        const exampleEmbed = new MessageEmbed()
    .setColor('#0099ff')
    .setTitle(action.options.getString('titulo'))
    .setDescription(action.options.getString('descrição'))
        .setImage('')
        action
        .client
        .channels
        .cache
        .find(channel => channel.name == "jornal")
        .send({ embeds: [exampleEmbed] })
        action.reply({ content: 'Sua notícia foi publicada!', ephemeral: false });
        action.deleteReply();
},
};

I can get the string values through the command "action.options.getString()" but there is no way to get the image I sent. I can use "action.options.get()", to get an object with the attachment name like this { name: "imagem", type: undefined, value: 123456789 }.

Is there a way to do it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can receive an attachment from a command interaction with .options.getAttachment()

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!