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

Check if value is equal to another value

What i am after:

I am developing a discord.js (V14) bot at the moment. The idea is the following. If a member executes the following / command:

/mute target:@member time:1d reason:spamming

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

Check if target:@member is equal to the bot it self.

My issue:

The below code should in theory (to my knownledge) be enough to check if the target:@member is equal to discord bot. However, my code completely skips that step. Even if i verify via console.log that both values are equal.

The Code:

10258xxxx – console.log(user.id);

10258xxxx – console.log(interaction.guild.members.me.id);

module.exports = {
    data: new SlashCommandBuilder()
        .setName("mute")
        .setDescription("Mute a member.")
        .addUserOption(option =>
            option.setName("target")
                .setDescription("Select the user you wish to mute.")
        )
        .addStringOption(option =>
            option.setName("time")
                .setDescription("How long should the mute last?")
        )
        .addStringOption(option =>
            option.setName("reason")
                .setDescription("What is the reason of the mute?")
        ),

    async execute(interaction) {
        const user = options.getUser("target");

        if (user.id === interaction.guild.members.me.id){
            return interaction.reply("I can't mute my self.");
        }

        return interaction.reply("Success");
    }

>Solution :

Not completely familiar with discord, but it looks like you might need to add the await keyword

return await interaction.reply("I can't mute my self.");

Without going into detail of how async await works, what you could test is the following to see that the line is running:

if (user.id === interaction.guild.members.me.id){
    console.log("Can you see me?");
    return interaction.reply("I can't mute my self.");
}

If you can see the log, what is happening is the code stops running before waiting for the async function to finish. If you want to understand this better, learn more about async await!

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