User need to be authorized bug

Hey, so everytime my partner managers try to run /partner or /partner-category they can't run because of this if statement blocking them to use it. I am a bit confused how to fix it because I have read over several stack overflow post that other users had similar bugs like me. This is my code below, and the role id is stored in a database
const roleId = interaction.guild.roles.fetch(yourGuildData.partnerRoleId);
const memberRoles = await interaction.member.fetch(interaction.user.id);
const userIsAuthorized = interaction.user.id === interaction.guild.ownerId || yourGuildData.managers?.includes(interaction.user.id) || memberRoles.roles.cache.has(roleId.id);
if (!userIsAuthorized) {
await interaction.reply("Only the server owner or authorized users can use this command.");
return;
}
const roleId = interaction.guild.roles.fetch(yourGuildData.partnerRoleId);
const memberRoles = await interaction.member.fetch(interaction.user.id);
const userIsAuthorized = interaction.user.id === interaction.guild.ownerId || yourGuildData.managers?.includes(interaction.user.id) || memberRoles.roles.cache.has(roleId.id);
if (!userIsAuthorized) {
await interaction.reply("Only the server owner or authorized users can use this command.");
return;
}
5 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Steve Jobs
Steve JobsOP9mo ago
meaning that I should await const roleId = interaction.guild.roles.fetch(yourGuildData.partnerRoleId);? I see so in other terms the code would be like this?
const roleId = yourGuildData.partnerRoleId
const userIsAuthorized = interaction.user.id === interaction.guild.ownerId || yourGuildData.managers?.includes(interaction.user.id) || interaction.user.roles.cache.has(roleId.id);
if (!userIsAuthorized) {
await interaction.reply("Only the server owner or authorized users can use this command.");
return;
}
const roleId = yourGuildData.partnerRoleId
const userIsAuthorized = interaction.user.id === interaction.guild.ownerId || yourGuildData.managers?.includes(interaction.user.id) || interaction.user.roles.cache.has(roleId.id);
if (!userIsAuthorized) {
await interaction.reply("Only the server owner or authorized users can use this command.");
return;
}
d.js docs
d.js docs9mo ago
Despite sounding similar there is a distinct difference between users and members in Discord: - User: global Discord user data (global avatar, username, tag, id) - GuildMember: user data associated to a guild (guild, nickname, roles, voice, guild avatar, etc.) - Conversion: User ➞ GuildMember | GuildMember ➞ User * Note: Events received in cached guilds will often have both the member and user available, eg. interaction.user and interaction.member
Steve Jobs
Steve JobsOP9mo ago
why not interaction.user.roles? Oh I see why thanks
Want results from more Discord servers?
Add your server