mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-23 01:25:02 +00:00
CustomEvents: check existing roles on addRoleAction
This commit is contained in:
parent
71351435c9
commit
6f0b3e0568
1 changed files with 6 additions and 3 deletions
|
@ -28,9 +28,12 @@ export async function addRoleAction(
|
||||||
if (event.trigger.type === "command" && !canActOn(pluginData, eventData.msg.member, target)) {
|
if (event.trigger.type === "command" && !canActOn(pluginData, eventData.msg.member, target)) {
|
||||||
throw new ActionError("Missing permissions");
|
throw new ActionError("Missing permissions");
|
||||||
}
|
}
|
||||||
|
const targetRoles = [...target.roles.cache.keys()];
|
||||||
const rolesToAdd = Array.isArray(action.role) ? action.role : [action.role];
|
const rolesToAdd = (Array.isArray(action.role) ? action.role : [action.role]).filter(id => !targetRoles.includes(id));
|
||||||
|
if (rolesToAdd.length === 0) {
|
||||||
|
throw new ActionError("Target already has the role(s) specified");
|
||||||
|
}
|
||||||
await target.edit({
|
await target.edit({
|
||||||
roles: Array.from(new Set([...target.roles.cache.values(), ...rolesToAdd])) as Snowflake[],
|
roles: Array.from(new Set([...targetRoles, ...rolesToAdd])) as Snowflake[],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue