Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discord js Slash command with embed ReferenceError: interaction is not define

"title": ${interaction.user.username}'s Profile
ReferenceError: interaction is not defined

const { SlashCommandBuilder } = require('discord.js');
const { EmbedBuilder } = require('discord.js');

const profileEmbed = {
    "type": "rich",
    "color": 0x00fff0,
    "title": `${interaction.user.username}'s Profile`
    "avatar": ?
                
}

module.exports = {
    data: new SlashCommandBuilder()
        .setName('profile')
        .setDescription('Replies with your profile!'),
    async execute(interaction) {
        await interaction.reply({embeds: [profileEmbed]});
    },
};

Is there a way that I can use interactions in "title" and with "avatar" aswell? I get "interaction is not defined" error when I run node deploy-commands.js file

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could always turn the profileEmbed object into a function that returns the object, and just pass in the interaction.

function profileEmbed(interaction) {
  return {
    "type": "rich",
    "color": 0x00fff0,
    "title": `${interaction.user.username}'s Profile`
    "avatar": ?   
  }
}
await interaction.reply({embeds: [profileEmbed(interaction)]})

This may not be what you’re looking for in terms of style, but it should accomplish what you’re trying to do.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading