<Collection>.hasAny() is not working
F0rce opened this issue · 2 comments
Issue description
As stated in the documentation, Collection has a function called hasAny()
which accepts an Array as argument.
But the hasAny()
function always returns false
eventhough the member has one of the given roles 100 %.
When using has()
it works perfectly fine.
Code sample
const roles = [ "roleid1", "roleid2" ];
// Not working logic
if (<message>.member.roles.cache.hasAny(roles)) {
console.log("Member has any of the roles");
}
// Working Logic (pretty inefficient)
let pass = false;
for (let i = 0; i < roles.length; i++) {
if (message.member.roles.cache.has(ignore[i])) {
pass = true;
}
}
if (pass) {
console.log("Member has any of the roles");
}
discord.js version
13.3.1
Node.js version
v16.13.0
Operating system
Linux
Priority this issue should have
Medium (should be fixed soon)
Which partials do you have configured?
CHANNEL
Which gateway intents are you subscribing to?
GUILDS, GUILD_MEMBERS, GUILD_PRESENCES, GUILD_MESSAGES, DIRECT_MESSAGES
I have tested this issue on a development release
No response
It takes rest params, change your code to:
- if (<message>.member.roles.cache.hasAny(roles)) {
+ if (<message>.member.roles.cache.hasAny(...roles)) {
And it'll work.
Edit: I just noticed, while in the code it's clear:
Lines 46 to 48 in 3f19298
The website does not indicate that it's rest parameters, but instead, that it takes an array as a single parameter:
I have no idea if our docsgen generates this information, but we should look into this.