Discord
To make your Chainlit app available on Discord, you will need to create a Discord app and set up the necessary environment variables.
How it Works
The Discord bot will listen to messages mentioning it in channels and direct messages. It will send replies to a dedicated thread or DM depending on the context.
Preview
Supported Features
Message | Streaming | Elements | Audio | Ask User | Chat History | Chat Profiles | Feedback |
---|---|---|---|---|---|---|---|
✅ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ |
Install the Discord Library
The Discord library is not included in the Chainlit dependencies. You will have to install it manually.
Create a Discord App
To start, navigate to the Discord apps dashboard. Here, you should find a button that says New Application. When you click this button, select the option to create your app from scratch.
Create a Discord App
Set the Environment Variables
Navigate to the Bot tab and click on Reset Token
. This will make the token visible. Copy it and set it as an environment variable in your Chainlit app.
Copy the Bot Token
Set Intents
Navigate to the Bot tab and enable the MESSAGE CONTENT INTENT
, then click on Save Changes.
Set Intents
Working Locally
If you are working locally, you will have to expose your local Chainlit app to the internet to receive incoming messages to Discord. You can use ngrok for this.
Start the Chainlit App
Since the Chainlit app is not running, the Discord bot will not be able to communicate with it.
For the example, we will use this simple app:
Start the Chainlit app.
Using -h to not open the default Chainlit UI since we are using Discord.
Install the Discord Bot to Your Workspace
Navigate to the OAuth2 tab. In the OAuth2 URL Generator, select the bot
scope.
Configure Installation
Then, in the Bot Permissions section, select the following permissions.
You can check that you have selected the right permissions by looking at the
number of permissions parameter of the URL. It should be 377957238848
.
Bot Permissions
Copy the generated URL and paste it in your browser. You will be prompted to add the bot to a server. Select the server you want to add the bot to.
That’s it! You should now be able to interact with your Chainlit app through Discord.
Chat History
Chat history is directly available through discord.
Was this page helpful?