0

I am trying to create a command, in this case it is activated with / attack, the mechanism I am looking for is that if the target user (mentioned) has the role (Lavander) which is a kind of shield, send an embed message saying defended and remove the role from you (break the shield) and if the target user (mentioned) does not have the shield role, just send a different message saying attacked. This is the code that I have been doing but it does not work for me even if it does not give errors, simply when using it, it ignores the role detection and sends both messages for some reason that I do not know, can someone help me?

    if (message.content.startsWith('/attack')) {

  let Lavander = message.guild.roles.cache.find(role => role.name == "Lavander");
  let member = message.mentions.members.first();

  if (message.member.roles.cache.has(Lavander)) return
  member.roles.remove(Lavander);
  message.channel.send(new Discord.MessageEmbed()
    .setColor("GOLD")
    .setTitle(message.author.username)
    .setDescription("Defended"))

  message.channel.send(new Discord.MessageEmbed()
    .setColor("GOLD")
    .setTitle(message.author.username)
    .setDescription("Attacked"))
}

2 Answers2

0

For me it seems like let Lavander = message.guild.roles.cache.find(role => role.name == "Lavander"); might be supposed to be let Lavander = message.guild.roles.cache.find(role => role.name === 'Lavander'); but without the info about the glitches and/or errors, I can't tell you anything else.

Pandicon
  • 420
  • 1
  • 15
  • 38
0

method collection.has require id as property. So you need somethink like this:

bot.on('message', (message) => {
    if (message.content.startsWith('/attack')) {
        let lavander = message.guild.roles.cache.find((role) => role.name === 'Lavander');
        let member = message.mentions.members.first();
        if (!member || !lavander) return message.reply('No role or member');
        if (message.member.roles.cache.has(lavander.id)) {
            member.roles.remove(lavander);
            let embed = new Discord.MessageEmbed()
                .setColor('GOLD')
                .setTitle(message.author.username)
                .setDescription('Defended');
        } else {
            let embed = new Discord.MessageEmbed()
                .setColor('GOLD')
                .setTitle(message.author.username)
                .setDescription('Attacked');
            message.channel.send(embed);
        }
    }
});
Cipher
  • 2,702
  • 1
  • 6
  • 17