> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Discord integration

> Integrate with the Discord tool using LangChain Python.

This guide provides a quick overview for getting started with Discord tooling in [langchain\_discord](/oss/python/integrations/tools/). For more details on each tool and configuration, see the docstrings in your repository or relevant doc pages.

## Overview

### Integration details

| Class                                       | Package                                                                                 | Serializable | [JS support](https://js.langchain.com/docs/integrations/tools/langchain_discord) |                                                  Version                                                 |
| :------------------------------------------ | :-------------------------------------------------------------------------------------- | :----------: | :------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------: |
| `DiscordReadMessages`, `DiscordSendMessage` | [`langchain-discord-shikenso`](https://github.com/Shikenso-Analytics/langchain-discord) |      N/A     |                                        TBD                                       | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-discord-shikenso?style=flat-square\&label=%20) |

### Tool features

* **`DiscordReadMessages`**: Reads messages from a specified channel.
* **`DiscordSendMessage`**: Sends messages to a specified channel.

## Setup

The integration is provided by the `langchain-discord-shikenso` package. Install it as follows:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install --quiet -U langchain-discord-shikenso
```

### Credentials

This integration requires you to set `DISCORD_BOT_TOKEN` as an environment variable to authenticate with the Discord API.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export DISCORD_BOT_TOKEN="your-bot-token"
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import getpass
import os

# Example prompt to set your token if not already set:
# if not os.environ.get("DISCORD_BOT_TOKEN"):
#     os.environ["DISCORD_BOT_TOKEN"] = getpass.getpass("DISCORD Bot Token:\n")
```

You can optionally set up [LangSmith](https://smith.langchain.com?utm_source=docs\&utm_medium=cta\&utm_campaign=langsmith-signup\&utm_content=oss-python-integrations-tools-discord) for tracing or observability:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()
```

## Instantiation

Below is an example showing how to instantiate the Discord tools in `langchain_discord`. Adjust as needed for your specific usage.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_discord.tools.discord_read_messages import DiscordReadMessages
from langchain_discord.tools.discord_send_messages import DiscordSendMessage

read_tool = DiscordReadMessages()
send_tool = DiscordSendMessage()

# Example usage:
# response = read_tool({"channel_id": "1234567890", "limit": 5})
# print(response)
#
# send_result = send_tool({"message": "Hello from notebook!", "channel_id": "1234567890"})
# print(send_result)
```

## Invocation

### Direct invocation with args

Below is a simple example of calling the tool with keyword arguments in a dictionary.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
invocation_args = {"channel_id": "1234567890", "limit": 3}
response = read_tool(invocation_args)
response
```

### Invocation with ToolCall

If you have a model-generated `ToolCall`, pass it to `tool.invoke()` in the format shown below.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
tool_call = {
    "args": {"channel_id": "1234567890", "limit": 2},
    "id": "1",
    "name": read_tool.name,
    "type": "tool_call",
}

tool.invoke(tool_call)
```

## Chaining

Below is a complete example showing how you might integrate the `DiscordReadMessages` and `DiscordSendMessage` tools in a chain or agent with an LLM. This example assumes you have a function (like [`create_agent`](https://reference.langchain.com/python/langchain/agents/factory/create_agent)) that sets up a LangChain-style agent capable of calling tools when appropriate.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# Example: Using Discord Tools in an Agent

from langchain.agents import create_agent
from langchain_discord.tools.discord_read_messages import DiscordReadMessages
from langchain_discord.tools.discord_send_messages import DiscordSendMessage


# 1. Instantiate or configure your language model
# (Replace with your actual LLM, e.g., ChatOpenAI(temperature=0))
model = ...

# 2. Create instances of the Discord tools
read_tool = DiscordReadMessages()
send_tool = DiscordSendMessage()

# 3. Build an agent that has access to these tools
agent_executor = create_agent(model, [read_tool, send_tool])

# 4. Formulate a user query that may invoke one or both tools
example_query = "Please read the last 5 messages in channel 1234567890"

# 5. Execute the agent in streaming mode (or however your code is structured)
stream = agent_executor.stream_events(
    {"messages": [("user", example_query)]},
    version="v3",
)

# 6. Print out the model's responses (and any tool outputs) as they arrive
for snapshot in stream.values:
    snapshot["messages"][-1].pretty_print()
```

***

## API reference

See the docstrings in:

* [discord\_read\_messages.py](https://github.com/Shikenso-Analytics/langchain-discord/blob/main/langchain_discord/tools/discord_read_messages.py)
* [discord\_send\_messages.py](https://github.com/Shikenso-Analytics/langchain-discord/blob/main/langchain_discord/tools/discord_send_messages.py)
* [toolkits.py](https://github.com/Shikenso-Analytics/langchain-discord/blob/main/langchain_discord/toolkits.py)

for usage details, parameters, and advanced configurations.

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/tools/discord.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
