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
d.js toolkit
d.js toolkit16mo 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!
space
space16mo ago
You can use interaction.inCachedGuild() as a guard. role instanceof Role (Role being imported from discord.js) works too
MrQuickLine
MrQuickLineOP16mo ago
Maybe 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 type /config role (where this is an application command with option type: 8) and give me a role to ping when so and so happens.
The autocomplete options for /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.
d.js docs
d.js docs16mo ago
property Role#managed Whether or not the role is managed by an external service
MrQuickLine
MrQuickLineOP16mo ago
I see. I'll dig into that. Thanks!
Want results from more Discord servers?
Add your server