How to limit a slash command to a specific role?
node = 18.16.0
discordjs = 14.11.0
23 Replies
• 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.and to a specific channel
you can check that with if
You can limit the slash command to a specific perms using the builder itself.
.setDefaultMemberPermissions()
exist.
But if you wanna check for a role. Do a check on the roles cache of the interaction member object.
And see if they have the role ID that you're looking for.
And use an if for the channel ID as well using the interaction.channelId
how for the channel?
thanks
and i have another problem, when this command is run it adds a role to a member and then remove another role from the member but it only remove the role it don’t adds the other role
whit no errors on the log
Show us how you handle that
member.roles.add()
member.roles.remove()
Use await
on both
ok
Those are promise based actions
And make sure the IDs are right as well
For example you can also use
await member.roles.add().then(m => m.roles.remove())
if you want it to happen in a certain order.it still only remove the role, but if i only try to add the role it add it
i’ll try
. you still didn't show the exact code snippet
dont forget that await requires the function to be async
it is
I think the IDE throws an error if the top level function is not async based
Before being executed
Please show your code where you handle that.
If it's too long use source bin or smth like that.
Maybe there's something else wrong in the code if it's not working.
you're right, thank you
it works
<:nb_cat_pat:851511871664029707>
np
Glad to hear that. Good luck
<a:seele_cheer:942760769618059284>
But the line by line await also should work
<:E_think:793918036787986453>
Without having to use then
you shine with happiness
first rule: if it works don’t touch it
and i don’t care about the order
thank you very much
@massicraft You can also use
member.roles.set
to add/remove multiple roles at once. https://old.discordjs.dev/#/docs/discord.js/14.11.0/class/GuildMemberRoleManager?scrollTo=setDiscord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.