fix: use async Attachment.read() instead of blocking requests.get in Discord client#8186
Merged
kausmeows merged 5 commits intoJun 1, 2026
Conversation
…Discord client The Discord on_message handler is an async event handler, but it called the synchronous, blocking requests.get() to download video and document attachments. A blocking network call inside a coroutine freezes the entire asyncio event loop for the full duration of the download, stalling every other message, typing indicator, and concurrent agent run handled by the bot. Replace requests.get(media_url) with discord.py's native await media.read(), which downloads the attachment without blocking the event loop. This also downloads through the bot's authenticated session, avoiding the 403 errors that plain HTTP downloads of Discord attachment URLs can hit. The now-unused requests import is removed.
The unit test suite does not install discord.py, so importing
agno.integrations.discord.client (which raises ImportError without it) failed
collection on CI. Guard the import with pytest.importorskip("discord").
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
DiscordClient's asyncon_messagehandler called the synchronous, blockingrequests.get()to download video and document attachments. A blocking network call inside a coroutine freezes the entire asyncio event loop for the full duration of the download, stalling every other message, typing indicator, and concurrent agent run handled by the bot.This replaces
requests.get(media_url)with discord.py's nativeawait media.read(), which downloads the attachment without blocking the event loop. It also downloads through the bot's authenticated session, avoiding the 403 errors that plain HTTP downloads of Discord attachment URLs can hit. The now-unusedrequestsimport is removed.Fixes #8185
Type of change
Checklist
Additional context
ruff checkandruff formatpass. Addslibs/agno/tests/unit/integrations/test_discord_client.pywith regression tests asserting the handler no longer usesrequests.getand reads attachments viaawait media.read().