Discord AI Bot with Cohere LLM Integration
Hey everyone,
A few months ago, I worked on a Discord bot that uses the Cohere API. I’m now happy to share the source code with you all.
The bot responds to commands and mentions in a Discord server, and it interacts with the Cohere API to generate responses.
If you are looking to build a similar bot or just want to see how it’s done, you can check out the code below.
Feel free to use it as a base for your own projects or to learn how to integrate Discord with an LLM. Click below image to download the code 👇
LOL, My Github has been Banned :(
After publishing this blog, account has been restored :)
But here is the source code you can use:
import discord
from discord.ext import commands
import cohere
import asyncio
import nest_asyncio
nest_asyncio.apply()
# Set up the Discord client with non-privileged intents
intents = discord.Intents.default()
intents.message_content = True
intents.reactions = True
allowed_mentions = discord.AllowedMentions(replied_user=True)
client = commands.Bot(command_prefix='!', intents=intents, allowed_mentions=allowed_mentions)
# Auth with Cohere
cohere_client = cohere.Client(api_key="your-cohere-api-key")
@client.event
async def on_ready()…