I have searched EVERYWHERE, and cannot find the answer.
So basically I’m making a role give & role remove command. I want to check if they already have the role, so I can stop the code. But it seems that everything I put after .roles
just stops working. For example, I’ve tried .has
,.remove
, .cache
, and .Contains
, none of those worked. Does anyone have a solution?
I’m a beginner at coding so I apologize if anything is just flat-out stupid.
module.exports = {
name: 'roleremove',
description: 'Removes a specified role from a user.',
// devOnly: Boolean,
// testOnly: Boolean,
// deleted: true,
options: [
{
name: 'user',
description: 'The user to remove the role from.',
required: true,
type: ApplicationCommandOptionType.User,
},
{
name: 'role',
description: 'The role you want to remove',
required: true,
type: ApplicationCommandOptionType.Role,
}
],
callback: async (client, interaction) => {
const targetUser = interaction.options.get('user').value;
const targetRole = interaction.options.get('role').value;
const alreadyHasRole = targetUser.roles.Contains(targetRole)
if (!alreadyHasRole) {
interaction.reply({ content: `❌ | Could not remove ${targetUser}'s role because they dont have that role.`, ephemeral: true });
} else {
await targetUser.roles.remove(targetRole);
interaction.reply({ content: `✅ | Successfully removed ${targetUser}'s role.`, ephemeral: true});
}
}
};```