-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Role management #294
base: main
Are you sure you want to change the base?
Role management #294
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Client } from "discord.js" | ||
|
||
export default async function manageRole( | ||
discordClient: Client, | ||
guildId: string, | ||
memberId: string, | ||
roleId: string, | ||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not convinced we'll find ourselves wanting to do this without having handles to at least the guild and maybe member objects already... For example, the first use we're pondering, which would be in reaction to the |
||
action: "add" | "remove", | ||
): Promise<void> { | ||
if (!discordClient) { | ||
throw new Error("Discord client is not initialized.") | ||
} | ||
|
||
const guild = await discordClient.guilds.fetch(guildId) | ||
if (!guild) throw new Error("Guild not found.") | ||
|
||
const member = await guild.members.fetch(memberId) | ||
if (!member) throw new Error("Member not found.") | ||
|
||
const role = await guild.roles.fetch(roleId) | ||
if (!role) throw new Error("Role not found.") | ||
|
||
if (action === "add") { | ||
if (member.roles.cache.has(roleId)) { | ||
return | ||
} | ||
await member.roles.add(role) | ||
} else if (action === "remove") { | ||
if (!member.roles.cache.has(roleId)) { | ||
return | ||
} | ||
await member.roles.remove(role) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add this as an unexported helper to the renamed
role-management
script from #293 . If we do move to a directory for role management due to complexity, this can end up in ahelpers
file or similar.