Discord
Discord is an instant messaging, voice, and video communication platform widely used by communities of all types.
Installation and Setup
Install the langchain-discord-shikenso
package:
pip install langchain-discord-shikenso
You must provide a bot token via environment variable so the tools can authenticate with the Discord API:
export DISCORD_BOT_TOKEN="your-discord-bot-token"
If DISCORD_BOT_TOKEN
is not set, the tools will raise a ValueError
when instantiated.
Tools
Below is a snippet showing how you can read and send messages in Discord. For more details, see the documentation for Discord tools.
from langchain_discord.tools.discord_read_messages import DiscordReadMessages
from langchain_discord.tools.discord_send_messages import DiscordSendMessage
# Create tool instances
read_tool = DiscordReadMessages()
send_tool = DiscordSendMessage()
# Example: Read the last 3 messages from channel 1234567890
read_result = read_tool({"channel_id": "1234567890", "limit": 3})
print(read_result)
# Example: Send a message to channel 1234567890
send_result = send_tool({"channel_id": "1234567890", "message": "Hello from Markdown example!"})
print(send_result)
Toolkit
DiscordToolkit
groups multiple Discord-related tools into a single interface. For a usage example, see the Discord toolkit docs.
from langchain_discord.toolkits import DiscordToolkit
toolkit = DiscordToolkit()
tools = toolkit.get_tools()
read_tool = tools[0] # DiscordReadMessages
send_tool = tools[1] # DiscordSendMessage
Future Integrations
Additional integrations (e.g., document loaders, chat loaders) could be added for Discord. Check the Discord Developer Docs for more information, and watch for updates or advanced usage examples in the langchain_discord GitHub repo.