logging: multiple roles at once for onboarding

This commit is contained in:
Cynthia Foxwell 2025-04-24 13:55:40 -06:00
parent 636a52290e
commit 6cfe1a9e62
Signed by: Cynosphere
SSH key fingerprint: SHA256:H3SM8ufP/uxqLwKSH7xY89TDnbR9uOHzjLoBr0tlajk

View file

@ -133,26 +133,29 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
case AuditLogActions.MEMBER_ROLE_UPDATE: { case AuditLogActions.MEMBER_ROLE_UPDATE: {
const added = entry.after.$add != null; const added = entry.after.$add != null;
const isSelf = entry.user.id === entry.targetID; const isSelf = entry.user.id === entry.targetID;
const role = (entry.after.$add ?? entry.after.$remove)[0]; const roles = entry.after.$add ?? entry.after.$remove;
const plural = roles.length > 1 ? "s" : "";
channel channel
.createMessage({ .createMessage({
embeds: [ embeds: [
{ {
color: added ? COLOR_ADDED : COLOR_REMOVED, color: added ? COLOR_ADDED : COLOR_REMOVED,
title: `Member Role Updated`, title: `Member Role${plural} Updated`,
description: `<@${entry.user.id}> (${formatUsername(entry.user)}) ${added ? "added" : "removed"} role ${ description: `<@${entry.user.id}> (${formatUsername(entry.user)}) ${added ? "added" : "removed"} ${
added ? "to" : "from" roles.length > 1 ? `${roles.length} ` : ""
} ${isSelf ? "self" : `<@${entry.targetID}> (${formatUsername(entry.target.user)})`}`, }role${plural} ${added ? "to" : "from"} ${
isSelf ? "self" : `<@${entry.targetID}> (${formatUsername(entry.target.user)})`
}`,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
fields: [ fields: [
{ {
name: "Role", name: `Role${plural}`,
value: `<@&${role.id}> (${role.name})`, value: roles.map((role) => `<@&${role.id}> (${role.name})`).join("\n"),
}, },
], ],
footer: { footer: {
text: `Role ID: ${role.id}`, text: `Role ID${plural}: ${roles.map((role) => role.id).join(", ")}`,
}, },
}, },
], ],