Fix party buttons returning 'not found' after bot restart#161
Merged
Conversation
Agent-Logs-Url: https://github.com/psykzz/cogs/sessions/4b98e063-61f7-4d49-9e7f-874a3b1186e7 Co-authored-by: psykzz <1134201+psykzz@users.noreply.github.com>
All PartyView buttons share static custom_ids (party_signup, party_leave, etc). Without message_id, discord.py routes all button interactions to the last-registered view, causing 'party not found' for every other party after a bot restart. Pass message_id to add_view so each view is tied to its specific message.
Adds [p]party fix <id> (admin only) that: - Fetches the existing party message - Re-registers the persistent view bound to that message_id - Edits the message with a fresh embed + reattached buttons Useful for existing parties created before the persistent view routing fix, where buttons were broken after a bot restart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug where clicking the Sign Up / Leave / Edit / Delete buttons on a party embed returns "Party not found" after a bot restart.
Root Cause
PartyViewbuttons all share staticcustom_ids (party_signup,party_leave,party_edit,party_delete). When_register_persistent_viewscalledbot.add_view(view)without amessage_id, discord.py could only route eachcustom_idto a single view — the last one registered. Any party whose view was overwritten in this loop would fail with "party not found" on every button click.Changes
party/party.py—_register_persistent_views: passmessage_idtobot.add_view()so each view is bound to its specific embed message. Discord.py then routes by(message_id, custom_id)tuple, correctly isolating each party.party/party.py— new[p]party fix <party_id>command (admin/manage_guild): re-renders the embed and re-registers the persistent view for an existing party. Useful for parties created before this fix.Testing
python -m py_compile party/party.py✅message_idso button routing is isolated per party.[p]party fixcommand tested path: fetches message, callsadd_view(view, message_id=...), edits message with fresh embed + view.Risk
Low. The change to
_register_persistent_viewsis strictly additive (passing an extra kwarg). The newfixcommand is additive and gated behindadmin_or_permissions(manage_guild=True).