Skip to main content

An integration package connecting Discord and LangChain

Project description

langchain-discord

This package provides Discord tools and a toolkit for use with LangChain. It includes:

  • DiscordReadMessages: Read messages from a given Discord channel.
  • DiscordSendMessage: Send messages to a given Discord channel.
  • DiscordToolkit: A convenient toolkit that bundles these tools.

Installation

pip install -U langchain-discord

Environment Variable

Export your bot token so the tools can authenticate with the Discord API:

export DISCORD_BOT_TOKEN="your-discord-bot-token"

If this environment variable is not set, the tools will raise a ValueError when instantiated.


Usage

Direct Tool Usage

from langchain_discord.tools.discord_read_messages import DiscordReadMessages
from langchain_discord.tools.discord_send_messages import DiscordSendMessage

# Create instances of each tool
read_tool = DiscordReadMessages()
send_tool = DiscordSendMessage()

# Read the last 5 messages from channel 1234567890
read_result = read_tool({"channel_id": "1234567890", "limit": 5})
print(read_result)

# Send a message to the same channel
send_result = send_tool({"channel_id": "1234567890", "message": "Hello from Python!"})
print(send_result)

Using the Toolkit

You can also use DiscordToolkit to automatically gather both tools:

from langchain_discord.toolkits import DiscordToolkit

toolkit = DiscordToolkit()
tools = toolkit.get_tools()

# tools[0] should be DiscordReadMessages, tools[1] is DiscordSendMessage
read_tool = tools[0]
send_tool = tools[1]

# Example usage
print(read_tool({"channel_id": "1234567890", "limit": 5}))
print(send_tool({"channel_id": "1234567890", "message": "Hello from toolkit!"}))

Tests

If you have a tests folder (e.g. tests/unit_tests/), you can run them (assuming Pytest) with:

pytest --maxfail=1 --disable-warnings -q

Make sure your DISCORD_BOT_TOKEN is set or your tests are mocked so they don’t require a real token.


License

MIT License


Further Documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_discord_shikenso-1.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file langchain_discord_shikenso-1.1.1.tar.gz.

File metadata

  • Download URL: langchain_discord_shikenso-1.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.2 Linux/6.8.0-52-generic

File hashes

Hashes for langchain_discord_shikenso-1.1.1.tar.gz
Algorithm Hash digest
SHA256 72182dc0aef4804210f2375f3e63d7deca05c978db5be597a704f9fe40ea399e
MD5 ce57bb8adba8e431b9bb2d084de74029
BLAKE2b-256 9866cc9a773b60cebc409eca1009f69320930f143d48b41512ef7e225314a7af

See more details on using hashes here.

File details

Details for the file langchain_discord_shikenso-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_discord_shikenso-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6f200e09adda20f81ede08f9b38a809c845ff4a344b6f7ec269ab4912fbf07e4
MD5 1d5fa451ae5d36923ecbdf4d14d4c8a7
BLAKE2b-256 d32e1115b5e921657e50fa67085911f0d227d5772eddec182bab2199db8fd7b4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page