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.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

  • Download URL: langchain_discord_shikenso-1.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 7b714c325654d5a3af1491f47cee559f9900b55ed92e14b43740842d1a8618af
MD5 201f9bf6f33c9efd925ef7c8e2b5adb9
BLAKE2b-256 01b2324ebb172011773af904824dd29fe0c511b4eb3faa275335f1a5b2eb69a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_discord_shikenso-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e9000caf584f8a9401b7bd4fc79a2753b67de163038e0918ca0d7ed07f6f176
MD5 38753de5a56b1907fca62f66eeea5dbc
BLAKE2b-256 82361e9cd7fc9dc81353689fa40a8b01a50719c51b8da42f7fc93e6a5aeebaaa

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