This Discord chat bot integrates with OpenAI to provide AI-generated responses to messages in a specified channel.
Before running the bot, ensure you have the following:
- Node.js installed on your system
- Discord.js library (
discord.js
) - OpenAI library (
openai
)
- Clone this repository or create a new Node.js project.
- Install dependencies using npm:
npm install discord.js openai
- Obtain your Discord bot token from the Discord Developer Portal.
- Obtain your OpenAI API key and organization ID.
- Define your Discord bot token, OpenAI API key, and organization ID in the code.
- Define your custom channel ID (
CUSTOM_CHAT_BOT_CHANNEL
) where the bot will listen and respond. - Customize the bot's activity message in the
client.on('ready')
event. - Customize the message length limit (
msgLengthLimit
) and any additional bot behavior as needed.
To run the bot:
node your_bot_file.js
Replace your_bot_file.js
with the filename containing your bot's code.
- Listens to messages in a specified Discord channel (
CUSTOM_CHAT_BOT_CHANNEL
). - Ignores messages from bots and messages starting with '!'.
- Limits message length and prompts for summarization if exceeded.
- Retrieves previous messages from the channel and uses them as context for OpenAI chat completion.
- Responds with AI-generated messages using OpenAI's GPT-3.5 model.
- Ensure your bot has appropriate permissions in your Discord server.
- OpenAI usage may incur costs based on API usage and plan.
- Customize and expand the bot's functionality to suit your needs.
Be cautious when using AI-generated content, as it may not always be accurate or appropriate. Ensure compliance with Discord's Terms of Service and community guidelines.