Skip to content

Conversation

mifuyutsuki
Copy link
Contributor

Pull Request Type

  • Feature addition
  • Bugfix
  • Documentation update
  • Code refactor
  • Tests improvement
  • CI/CD pipeline enhancement
  • Other: [Replace with a description]

Description

The banner field in the Discord API User object is both nullable and can be missing.

When a User is fetched with force=True to obtain the banner value, due to how the data is processed, an Asset with hash=None may be erroneously created whose url points to None.png.

This fix makes User correctly process the null banner such that User.banner would become None in that case, rather than Asset(hash=None). The similar Member object processed banner correctly and is not affected by this bug.

Changes

  • Changed the banner field check in interactions.models.discord.user:User from if "banner" in data to if data.get("banner", None).
    • This sets the object's banner value to its default of None.

Related Issues

Test Scenarios

Select a user with no banner.

  • Bug: Asset(_url='https://cdn.discordapp.com/banners/<id>/None', hash=None)
  • Fixed: None
@slash_command(name="test", description="Test command")
@slash_option(name="user", description="User to view", opt_type=OptionType.USER, required=False)
async def test_cmd(ctx: SlashContext, user: Member | User | None = None):
  user = user or ctx.author
  fetched = await ctx.bot.fetch_user(user.id, force=True)
  if fetched:
    await ctx.send(str(fetched.banner))

Python Compatibility

  • I've ensured my code works on Python 3.10.x
  • I've ensured my code works on Python 3.11.x

Checklist

  • I've run the pre-commit code linter over all edited files
  • I've tested my changes on supported Python versions
  • I've added tests for my code, if applicable
  • I've updated / added documentation, where applicable

The `banner` field in the Discord API `User` object is both nullable and can be missing.

When a User is fetched with `force=True` to obtain the `banner` value, due to how the data is processed, an Asset with hash=None may be erroneously created, whose url points to `None.png`.

This fix makes User correctly process the null `banner` such that User.banner would become `None` in that case, rather than `Asset(hash=None)`. The similar Member object processed `banner` correctly and is not affected by this bug.
@silasary silasary merged commit 0d11f77 into interactions-py:unstable Jul 29, 2025
2 checks passed
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.

2 participants