fix: make ComponentEmoji id and name optional#91
Merged
shoucandanghehe merged 3 commits intoMay 18, 2026
Conversation
Discord only includes the `id` field for custom emojis, not for standard unicode emojis (e.g. 🔗). Defining `id` as required via `Field(...)` causes pydantic ValidationError when receiving MESSAGE_UPDATE events containing button components with unicode emojis. Change both `id` and `name` to use `Missing[...] = UNSET` to match the Discord API specification where both fields are optional in a partial emoji. Fixes nonebot#90
Discord only includes the id field for custom emojis, not for standard unicode emojis (e.g. 🔗). Defining id as required via Field(...) causes pydantic ValidationError when receiving MESSAGE_UPDATE events containing button components with unicode emojis. Change both id and ame to use Missing[...] = UNSET to match the Discord API specification where both fields are optional in a partial emoji. Fixes nonebot#90
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #91 +/- ##
==========================================
+ Coverage 75.76% 75.79% +0.03%
==========================================
Files 40 40
Lines 7286 7297 +11
Branches 380 380
==========================================
+ Hits 5520 5531 +11
Misses 1684 1684
Partials 82 82
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
lgtm, thx |
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.
Discord only includes the
idfield for custom emojis, not for standard unicode emojis (e.g. 🔗, 🟢, 🗑️). The current code definesidas required viaField(...)which causes pydanticValidationErrorwhen receivingMESSAGE_UPDATEevents containing button components with unicode emojis.Root Cause
In
nonebot/adapters/discord/api/model.py,ComponentEmojiis defined as:Per Discord API docs, the emoji in a button is a partial emoji where both
idandnameare optional.Fix
Change
idandnamefrom required to optional while preserving Discord field semantics:This follows Discord's nullable/optional field rules and models
idas a Snowflake.Tests
Added regression coverage for:
{"name": "🔗"}whereidis omittedidis nullable and parsed asSnowflakeError before fix
Closes #90