Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda