Skip to content

feat: persist and restore Discord member roles on rejoin#104

Open
swayam-agrahari wants to merge 2 commits intoamfoss:developfrom
swayam-agrahari:add_member_roles
Open

feat: persist and restore Discord member roles on rejoin#104
swayam-agrahari wants to merge 2 commits intoamfoss:developfrom
swayam-agrahari:add_member_roles

Conversation

@swayam-agrahari
Copy link

@swayam-agrahari swayam-agrahari commented Mar 12, 2026

Overview

Adds functionality to automatically persist a member's Discord roles when they leave the server and restore them when they rejoin.

Currently, when a user leaves and joins again, all their roles are lost and moderators must manually reassign them. This change automates that process.

How it works

  • When a member leaves (GuildMemberRemoval), their role IDs are collected and saved via the Root backend.
  • When the member rejoins (GuildMemberAddition), the bot fetches the stored roles and restores them automatically.

Notes

  • The @everyone role is excluded since it is implicitly assigned by Discord.
  • Role restoration errors (e.g., deleted roles or permission issues) are safely ignored to avoid breaking the event handler.

Related PR

This feature depends on the supporting backend changes in root:

➡ Supporting PR: pr link
Closes #93

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Discord role persistence across leave/rejoin events by saving a departing member’s role IDs to the Root backend and restoring those roles when the member rejoins.

Changes:

  • Request the GUILD_MEMBERS gateway intent to receive member add/remove events.
  • Persist role IDs on GuildMemberRemoval (excluding the @everyone role).
  • Restore persisted role IDs on GuildMemberAddition via new GraphQL client methods.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.

File Description
src/main.rs Captures roles on member removal and restores roles on member addition; adds GUILD_MEMBERS intent.
src/graphql/queries.rs Adds GraphQL mutation/query helpers to save and fetch persisted member roles.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@swayam-agrahari
Copy link
Author

@hrideshmg pls review this : )

@Viserion-7 Viserion-7 requested a review from hrideshmg March 14, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Role Persistence Feature

2 participants