Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda