-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat: Add modify function to the GuildMemberRoleManager for adding/removing roles at once. #10355
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Ignored Deployments
|
Yes, there is: https://discord.js.org/docs/packages/discord.js/14.15.3/GuildMemberRoleManager:Class#set Expanding on this further for specific use cases in user land is simple enough to do. |
Yea I did see this, and I had built it for my use case, it just felt like something that should and could easily be built into discordjs |
@@ -4393,6 +4393,12 @@ export class GuildStickerManager extends CachedManager<Snowflake, Sticker, Stick | |||
public fetchUser(sticker: StickerResolvable): Promise<User | null>; | |||
} | |||
|
|||
export interface ModifyGuildMemberRolesOptions { |
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.
Is this the right place to put this? What is the preference for ordering in the this typings file?
/** | ||
* Resolves roles from the input. | ||
* @param {Readonly<RoleResolvable[]> | ReadonlyCollection<Snowflake, Role>} rolesToResolve The roles to resolve | ||
* @returns {Role[]} The resolved roles |
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.
this is not what is returned by this function.
an array of role ids is returned.
as this is only used to resolve role ids and is private we should keep it as returning role ids as makes more sense. This will require a small change to the modify function as well.
@@ -4408,6 +4414,7 @@ export class GuildMemberRoleManager extends DataManager<Snowflake, Role, RoleRes | |||
roleOrRoles: RoleResolvable | readonly RoleResolvable[] | ReadonlyCollection<Snowflake, Role>, | |||
reason?: string, | |||
): Promise<GuildMember>; | |||
public modify(options: ModifyGuildMemberRolesOptions): GuildMember; |
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.
public modify(options: ModifyGuildMemberRolesOptions): GuildMember; | |
public modify(options: ModifyGuildMemberRolesOptions): Promise<GuildMember>; |
/** | ||
* Modifies the roles of the member. | ||
* @param {ModifyGuildMemberRolesOptions} [options] Options for modifying the roles | ||
* @returns {GuildMember} |
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.
* @returns {GuildMember} | |
* @returns {Promise<GuildMember>} |
* @property {Readonly<RoleResolvable[]> | ReadonlyCollection<Snowflake, Role>} [rolesToAdd] The roles to add | ||
* @property {Readonly<RoleResolvable[]> | ReadonlyCollection<Snowflake, Role>} [rolesToRemove] The roles to remove | ||
* @property {Readonly<RoleResolvable[]> | ReadonlyCollection<Snowflake, Role>} [reason] Reason for modifying | ||
* the roles |
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.
do we have a typedef for ReadonlyCollection and Readonly
Please describe the changes this PR makes and why it should be merged:
The GuildMemberRoleManager class has an add & remove function which, when given multiple roles, use the GuildMemberManager.edit function which utilizes Modify Guild Member endpoint allowing discord.js to add/remove multiple roles in a single api call. However, there is no function for adding and removing multiple roles at once, this PR adds one.
Additionally, the add/remove functions in the GuildMemberRoleManager both used the same logic for resolving a list of roles. This PR moves that logic into a shared function both can use, as well as the new modify function.
Status and versioning classification: