Command not running despite meeting the requirements

.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;
}
.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
5 Replies
d.js toolkit
d.js toolkit2y ago
• 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.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
scotty
scottyOP2y ago
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;
}
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;
}
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
scotty
scottyOP2y ago
thank you!
Want results from more Discord servers?
Add your server