How to make a slash command respond with an embed to a certain person

Viewed 105
const ms = require('ms');
const { EmbedBuilder } = require('discord.js');
const { ApplicationCommandType, ApplicationCommandOptionType } = require('discord.js');

module.exports = {
    name: 'profile',
    description: 'View the profile of a certain user',
    voiceChannel: false,
    options: [
    {
        name: 'user',
        description: 'Select a user',
        type: ApplicationCommandOptionType.User,
        required: true,
    }
    ],

async execute({ inter }) {

const error = new EmbedBuilder()
.setColor('#ff0000')
.setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
.setTitle('❌ Error')
.setDescription('There was an error whilst executing this command!')
.setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })});

const MYPROFILE1 = new EmbedBuilder()
.setColor('#5679EF')
.setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
.setTitle('⚙ My Profile')
.addFields(
    { name: 'lots of things here', value: 'things i guess' },
)
.setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })});

const MYPROFILE2 = new EmbedBuilder()
.setColor('#5679EF')
.setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
.setTitle('⚙ My Profile')
.addFields(
    { name: 'Profile', value: 'it worked' },
)
.setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })});

    const user1 = inter.options.getUser('user');
    if (user1 == "Coke#0666") return inter.reply({ embeds: [error], ephemeral: true })
    await inter.reply({ embeds: [MYPROFILE1] })

    if (user1 == "Clorophyte#9014") return inter.reply({ embeds: [MYPROFILE1], ephemeral: true })

},
};

Above is my block of code and I have been trying to make it so that if a certain user selects my profile it will respond with a certain embed. I have tried many times but to no avail.

Oh and if someone doesn't enter in a username that hasn't been specified, how do I make an else if statement in this situation?

Now I did try some people's suggestions but it just sends the error embed instead of the correct embed I want it to reply with

1 Answers

For the bot to respond to a certain user only, use ephemeral:

if (user1 !== "Coke#0666") return inter.reply({ embeds: [error], ephemeral: true })
await inter.reply({ embeds: [MYPROFILE1], ephemeral: true })

Edit:

if (user1.tag === "Coke#0666") return inter.reply({ embeds: [embed1] })
else if (user1.tag === "KNguyen#8442") return inter.reply({ embeds: [embed2] })
// else if ...
else return inter.reply({ embeds: [embedn] })
Related