#Command not running despite meeting the requirements

7 messages · Page 1 of 1 (latest)

mystic pilot
#
   .addStringOption((option) =>
      option
        .setName("rank")
        .setDescription("Your respective rank")
        .setRequired(true)
        .addChoices(
          { name: "I", value: "I", roleId: "1051888647961575464" },
          { name: "C", value: "C", roleId: "989618534009159740" },
          { name: "E", value: "E", roleId: "989618534629916732" },
          { name: "RM", value: "RM", roleId: "1069139407204007986" },
          { name: "DD", value: "DD", roleId: "1056906050403573760" },
          { name: "BD", value: "BD", roleId: "899869665780719667" }
        )
    ),

  async execute(interaction) {
    let user = interaction.options.getString("username");
    let link = interaction.options.getString("link");
    let division = interaction.options.getString("division");
    let rank = interaction.options.getString("rank");

    
   const selectedRank = interaction.options.get("rank");
    const selectedRoleId = selectedRank.value.roleId;
    
    if (!interaction.member.roles.cache.has(selectedRoleId)) {
        await interaction.reply("You do not have permission to select that rank!");
        return;
    }

expected to only be able to select the role if you have the roleid tied to the rank - but the message 'You do not have permission to select that rank!' occurs despite having the correct role to select the rank. No errors

rocky stormBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

lapis thunder
#

selectedRank does not have a roleId property. you can get the string option choice value by using interaction.options.getString('rank'), but still does not have a roleId property because String#roleId doesn’t exist so you can’t use that

#

the getString(…) will return the value

#

also you can’t add your own property to addChoices i just noticed that

mystic pilot
#

yep feel so stupid 🤦

fixed it with

    const rankRoles = {
        "I": "1051888647961575464",
        "C": "989618534009159740",
        "E": "989618534629916732",
        "RM": "1069139407204007986",
        "DD": "1056906050403573760",
        "BD": "899869665780719667"
    };
    const selectedRank = interaction.options.getString("rank");
    const selectedRoleId = rankRoles[selectedRank];
    
    if (!interaction.member.roles.cache.has(selectedRoleId)) {
        await interaction.reply("You do not have permission to select that rank!");
        return;
    }
lapis thunder
#

alright as long as it’s working 🙂