Skip to content
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

community: add Discord send and read message tools #29690

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

hemati
Copy link

@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 This PR changes 100-499 lines, ignoring generated files. 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 Related to langchain-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
Author

hemati commented Feb 8, 2025

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

@hemati
Copy link
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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Related to langchain-community size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Triage
Development

Successfully merging this pull request may close these issues.

1 participant