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

306
Views
Is there any way to make a command in discord js that allows the user to choose an image (image path from local) and send it

I've been looking up how to send an image with a bot command and only found how to send the same image from the repo of the project or a static URL, but I didn't see how to make a command that allows the user to choose an image and send it. I need this feature to make a bot command that sends an announcement in a specific channel, and including an image in that announcement should be optional.

I've tried this:

async execute(interaction) {
    if (!interaction.member.roles.cache.some((role) => role.name === "admin")) {
        await interaction.reply(`You don't have access !`);
        return;
    } else {
        const { MessageAttachment, MessageEmbed } = require("discord.js");
        //extracting the image path
        const image_path = interaction.options.getString("image_path");
        const file = new MessageAttachment(image_path);
        const exampleEmbed = new MessageEmbed().setTitle("Announcement image").setImage(image_path);
        //converting the msg to string
        const message = interaction.options.getString("message");
        await interaction.reply(`${message} message sent !`);
        channel.send({ embeds: [exampleEmbed], files: [file] });
    }
}
about 4 years ago · Juan Pablo Isaza
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!