Skip to content

community: add Discord send and read message tools #29690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from

Conversation

hemati
Copy link
Contributor

@hemati hemati commented Feb 8, 2025

PR message:

Description:
This PR introduces a new Discord integration to the LangChain community tools. It adds a DiscordClientWrapper in libs/community/langchain_community/tools/discord/base.py that leverages aiohttp to perform asynchronous HTTP requests to the Discord REST API. The wrapper provides two key functionalities:

  • send_message: Sends messages to a specified Discord channel.
  • read_messages: Retrieves a specified number of recent messages from a Discord channel.

In addition, two new tools have been added:

  • DiscordSendMessage (in libs/community/langchain_community/tools/discord/send_message.py): A tool for sending messages. It includes both synchronous and asynchronous interfaces, input validation using Pydantic, and robust error handling.
  • DiscordReadMessages (in libs/community/langchain_community/tools/discord/read_messages.py): A tool for reading messages from a Discord channel, also featuring both sync and async interfaces along with proper validation and error handling.

This integration follows best practices for secure token management (via the DISCORD_BOT_TOKEN environment variable), asynchronous processing, and error logging, and it adheres to the established LangChain tool structure.

Issue:
N/A

Dependencies:
This change introduces an optional dependency on aiohttp for asynchronous HTTP operations. The dependency is only imported within the functions that require it.

hemati and others added 2 commits February 8, 2025 20:51
- Introduce `DiscordClientWrapper` in `tools/discord/base.py` that uses aiohttp to interact with the Discord REST API.
  - Added asynchronous `send_message` method for posting messages.
  - Added asynchronous `read_messages` method for retrieving messages.
- Add `DiscordSendMessage` tool in `tools/discord/send_message.py` with pydantic input validation and both sync (via asyncio.run) and async interfaces.
- Add `DiscordReadMessages` tool in `tools/discord/read_messages.py` to read messages from a channel, with proper error handling and input validation.
@dosubot dosubot bot added the size:L label Feb 8, 2025
Copy link

vercel bot commented Feb 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 9, 2025 8:24am

@dosubot dosubot bot added the community label Feb 8, 2025
…ools

- Updated DiscordReadMessages description to improve line wrapping.
- Adjusted DiscordSendMessageSchema description to ensure consistent formatting.
…ools

- Updated DiscordReadMessages description to improve line wrapping.
- Adjusted DiscordSendMessageSchema description to ensure consistent formatting.
@hemati
Copy link
Contributor Author

hemati commented Feb 8, 2025

can somebody help. i cant seem to find the error here :(

@hemati
Copy link
Contributor Author

hemati commented Feb 9, 2025

Hey, I’ve resolved the lint/test issues by adding:

# type: ignore[override, override]

in the same spots as in the other tools. This makes it consistent with the existing LangChain codebase and fixes the override warning. Everything now passes successfully. Let me know if there’s anything else you’d like me to address!

@efriis
Copy link
Contributor

efriis commented Feb 13, 2025

Hey! This adds a net-new community integration or feature, which has been replaced by dedicated integration packages. I'll close this PR, and would recommend reopening with just docs updates, as well as registering your package in libs/packages.yml! We'll be able to review simple PRs that only modify these two things much faster :)

Here's the guide, and if you have questions, feel free to leave them in the comments on those pages so others can see them! https://python.langchain.com/docs/contributing/how_to/integrations/

@efriis efriis closed this Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants