Precondition issue

. I have this code, but for some reason it deletes the message even if the member has any of the roles in the array
8 Replies
-Carlos👑
-Carlos👑OP•15mo ago
No description
No description
ararou!
ararou!•15mo ago
what "hasAny" i just use
export const isStaff = function (member: GuildMember) {
return (
container.config.guild.roles.owner.some((role: string) =>
member.roles.cache.has(role),
) ||
container.config.guild.roles.admin.some((role: string) =>
member.roles.cache.has(role),
) ||
container.config.guild.roles.head.some((role: string) =>
member.roles.cache.has(role),
) ||
container.config.guild.roles.staff.some((role: string) =>
member.roles.cache.has(role),
) ||
container.config.dev.includes(member.user.id)
);
};
export const isStaff = function (member: GuildMember) {
return (
container.config.guild.roles.owner.some((role: string) =>
member.roles.cache.has(role),
) ||
container.config.guild.roles.admin.some((role: string) =>
member.roles.cache.has(role),
) ||
container.config.guild.roles.head.some((role: string) =>
member.roles.cache.has(role),
) ||
container.config.guild.roles.staff.some((role: string) =>
member.roles.cache.has(role),
) ||
container.config.dev.includes(member.user.id)
);
};
for my staff check function and then
export default class Staff extends Precondition {
public override async messageRun(message: Message) {
return this.container.utils.checks.isStaff(message.member!)
? this.ok()
: this.error({
message: "Stop trying to use this command, it's for staff only.",
});
}
}
export default class Staff extends Precondition {
public override async messageRun(message: Message) {
return this.container.utils.checks.isStaff(message.member!)
? this.ok()
: this.error({
message: "Stop trying to use this command, it's for staff only.",
});
}
}
but yea using yourconfig.roles.some((role) => <GuildMember>.roles.cache.has(role)); will work
-Carlos👑
-Carlos👑OP•15mo ago
ty
Lioness100
Lioness100•15mo ago
I actually think using hasAny is a good way to go. Ararou might've been confused because it's a relatively new addition to the Collection API. @_carlos123 could you show your original code? For example, @Ararou's utility function could be simplified to:
export const isStaff = function (member: GuildMember) {
return (
member.roles.cache.hasAny(
...container.config.guild.roles.owner,
...container.config.guild.roles.admin,
...container.config.guild.roles.head,
...container.config.guild.roles.staff
) || container.config.dev.includes(member.user.id)
);
};
export const isStaff = function (member: GuildMember) {
return (
member.roles.cache.hasAny(
...container.config.guild.roles.owner,
...container.config.guild.roles.admin,
...container.config.guild.roles.head,
...container.config.guild.roles.staff
) || container.config.dev.includes(member.user.id)
);
};
ararou!
ararou!•15mo ago
oh eh ill test it out in a test build of the bot and look up on it i am hardly informed on some changes abt d.js 😅
-Carlos👑
-Carlos👑OP•15mo ago
rest parameters are not d.js message.member.roles.cache.hasAny(roles) guessing it would need to be message.member.roles.cache.hasAny(...roles)
Lioness100
Lioness100•15mo ago
Yes @Carlos1996 So sorry for the ping @_carlos123 is who I meant
ararou!
ararou!•15mo ago
either way
Want results from more Discord servers?
Add your server