feat: add verified role auto-grant cog#6
feat: add verified role auto-grant cog#6devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
Co-Authored-By: Oliver Ni <oliver.ni@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Closing due to inactivity for more than 7 days. Configure here. |
| limit=10, | ||
| ): | ||
| if entry.target and entry.target.id == after.id: | ||
| if any(r.name in TRIGGER_ROLE_NAMES for r in entry.changes.after.roles): |
There was a problem hiding this comment.
🔴 Unhandled AttributeError when audit log entry is a role-removal-only action
On line 59, entry.changes.after.roles is accessed inside a try/except that only catches discord.Forbidden and discord.HTTPException. In discord.py, AuditLogDiff attributes are set dynamically: for member_role_update entries, $add populates after.roles and $remove populates before.roles. If one of the 10 fetched audit log entries targeting the same member is a role removal (no roles added), entry.changes.after won't have a roles attribute, raising AttributeError. This is not caught by the except clause, so the entire on_member_update handler crashes—meaning the log message to the channel is never sent.
Example crash scenario
A moderator removes some role from the member shortly before (or concurrently with) adding a trigger role. The audit log now has a removal entry for the same member within the last 10 member_role_update entries. The loop hits that entry first, entry.target.id == after.id matches, and entry.changes.after.roles raises AttributeError.
| if any(r.name in TRIGGER_ROLE_NAMES for r in entry.changes.after.roles): | |
| if hasattr(entry.changes.after, 'roles') and any(r.name in TRIGGER_ROLE_NAMES for r in entry.changes.after.roles): |
Was this helpful? React with 👍 or 👎 to provide feedback.
|
Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it. |
feat: add verified role auto-grant cog
Summary
Adds a new
Verifiedcog that automatically grants the Verified role whenever Logistics or Problem Writing is added to a member. Includes:on_member_updatelistener that detects trigger role additions, grants Verified, and looks up the audit log to identify who added the roleintents.members(privileged intent) on the botReview & Testing Checklist for Human
intents.members = Truerequires the "Server Members Intent" toggle to be enabled in the Discord Developer Portal. If not already on, the bot will fail to connect after this change.entry.changes.after.roleson line 63 may raiseAttributeErrorifentry.changes.afterisNoneor lacks a.rolesattribute — the surroundingtry/exceptonly catchesdiscord.Forbiddenanddiscord.HTTPException, notAttributeError. Worth verifying against the discord.py docs or testing live.1471399531580100670and role names"Verified","Logistics","Problem Writing"match the actual server configuration exactly (case-sensitive).Notes