How do I distinguish an `APIRole` from a `Role`?
In a CommandInteraction, if you set one of the options to
type: 8
for Role, the user can pass in an APIRole
if they want. (I think that's a separate problem that needs to be solved, but in the meantime...) Is there an easy way to check if they've passed in a Role
or an APIRole
?5 Replies
- 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!You can use
interaction.inCachedGuild()
as a guard.
role instanceof Role
(Role
being imported from discord.js) works tooMaybe I misunderstood something...
I create a Bot called 'Foo' and I add it to a server. It automatically gets assigned a role 'Foo' (which I will now refer to as FooBot and FooRole). In the Server Settings under Roles, if you click 'FooRole' it gives you the big warning:
This role is managed by an integration, yada yada yada".FooBot says,
Hey, server admin! You can typeThe autocomplete options for/config role
(where this is an application command with optiontype: 8
) and give me a role to ping when so and so happens.
/config role
includes FooRole. Ideally - I don't want the autocomplete to include that role. But if it must be included, then I want to do something in my code with interaction.reply({message: "That's not a valid role. Choose a role that didn't come in with a bot!"})
Is FooRole
an APIRole
? I assumed yes.I see. I'll dig into that. Thanks!