diff options
| author | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-07-15 13:56:24 +0100 |
|---|---|---|
| committer | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-07-15 13:56:24 +0100 |
| commit | a8cd84b8291990265dbdddcdaa079886234180a1 (patch) | |
| tree | 20dec2454dc7ee331f29d53b339f0f26a384b56a /174bg/discord-bot/utilities/notifyRoleByName.js | |
| parent | c488c4840588fd88fa840306c40ab99ebb3512b9 (diff) | |
| download | unnamed-group-a8cd84b8291990265dbdddcdaa079886234180a1.tar unnamed-group-a8cd84b8291990265dbdddcdaa079886234180a1.tar.gz unnamed-group-a8cd84b8291990265dbdddcdaa079886234180a1.tar.bz2 unnamed-group-a8cd84b8291990265dbdddcdaa079886234180a1.tar.xz unnamed-group-a8cd84b8291990265dbdddcdaa079886234180a1.zip | |
refactor codebase for dry
Diffstat (limited to '174bg/discord-bot/utilities/notifyRoleByName.js')
| -rw-r--r-- | 174bg/discord-bot/utilities/notifyRoleByName.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/174bg/discord-bot/utilities/notifyRoleByName.js b/174bg/discord-bot/utilities/notifyRoleByName.js new file mode 100644 index 0000000..1b2b82a --- /dev/null +++ b/174bg/discord-bot/utilities/notifyRoleByName.js @@ -0,0 +1,19 @@ +export default async (guild, roleName, message) => { + // get the role by name + const role = guild.roles.cache.find( + (role) => role.name.toLowerCase() === roleName.toLowerCase(), + ); + + if (!role) { + console.error(`Role "${roleName}" not found.`); + return; + } + + // get all members with the role + const membersWithRole = role.members; + + // send a DM to each member with the role + for (const member of membersWithRole.values()) { + await member.send(message); + } +}; |
