Use Honcho to build a Discord bot with conversational memory and context management.
Example code is available on GitHubAny application interface that defines logic based on events and supports special commands can work easily with Honcho. Here’s how to use Honcho with Discord as an interface. If you’re not familiar with Discord bot application logic, the py-cord docs would be a good place to start.
py-cord
that listens for messages. We use a helper function validate_message()
to check if the message should be processed.
to_openai()
method to automatically convert the session context into the format expected by OpenAI’s chat completions API.
add_messages()
method. The peer.message()
creates a message from the user, while assistant.message()
creates a message from the assistant.
honcho_client
: The main Honcho clientassistant
: A peer representing the bot/assistantopenai
: OpenAI client configured to use OpenRoutersession.get_context().to_openai()
automatically formats chat historysession.add_messages()
stores both user and assistant messagespeer.chat()
enables querying conversation history