A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://python.langchain.com/docs/integrations/tools/discord below:

Discord | 🦜️🔗 LangChain

Discord

This notebook provides a quick overview for getting started with Discord tooling in langchain_discord. For more details on each tool and configuration, see the docstrings in your repository or relevant doc pages.

Overview Integration details Tool features Setup

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

%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.

export DISCORD_BOT_TOKEN="your-bot-token"

You can optionally set up LangSmith for tracing or observability:

Instantiation

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

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

read_tool = DiscordReadMessages()
send_tool = DiscordSendMessage()







Invocation Direct invocation with args

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

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.

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 more 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_react_agent) that sets up a LangChain-style agent capable of calling tools when appropriate.



from langgraph.prebuilt import create_react_agent
from langchain_discord.tools.discord_read_messages import DiscordReadMessages
from langchain_discord.tools.discord_send_messages import DiscordSendMessage



llm = ...


read_tool = DiscordReadMessages()
send_tool = DiscordSendMessage()


agent_executor = create_react_agent(llm, [read_tool, send_tool])


example_query = "Please read the last 5 messages in channel 1234567890"


events = agent_executor.stream(
{"messages": [("user", example_query)]},
stream_mode="values",
)


for event in events:
event["messages"][-1].pretty_print()
API reference

See the docstrings in:

for usage details, parameters, and advanced configurations.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4