discord-chatgpt-lib
is a simple Node.js library that allows you to create a ChatGPT-powered Discord bot. The library provides an easy-to-use interface to handle incoming messages, generate responses using OpenAI's Chat API, and send the responses back to the Discord channel.
To install the library, use the following command:
npm install discord-chatgpt-lib
- Import the library and create an instance of
DiscordChatGPT
:
const token = 'YOUR_DISCORD_BOT_TOKEN';
const apiKey = 'YOUR_OPENAI_API_KEY';
const options = {
channelId: 'YOUR_CHANNEL_ID', // Optional: The ID of the channel to listen to
channelName: 'YOUR_CHANNEL_NAME', // Optional: The name of the channel to listen to
messageToSend: 'Bot Response: {response}', // Optional: Customize the message format
logger: true, // Optional: Set to false to disable logging
};
const bot = new DiscordChatGPT(token, apiKey, options);
-
Start the bot:
bot.start();
-
Replace
YOUR_DISCORD_BOT_TOKEN
with your actual Discord bot token andYOUR_OPENAI_API_KEY
with your OpenAI API key. Adjust the options object as needed, providing the channel ID or name to listen to, customizing the message format, and enabling or disabling logging. -
Run your Node.js application:
node index.js
-
Your Discord bot is now running and ready to respond to messages in the specified channel(s) using ChatGPT.
token
(required): Your Discord bot token.
apiKey
(required): Your OpenAI API key.
options
(optional): An object containing additional configuration options.
-
channelId
(optional): The ID of the channel to listen to. If provided, the bot will only respond to messages in that channel. -
channelName
(optional): The name of the channel to listen to. If provided, the bot will only respond to messages in that channel. -
messageToSend
(optional): The message format to be sent in the channel. The string{response}
will be replaced with ChatGPT's response. Default is'{response}'
. -
logger
(optional): A boolean value indicating whether the bot should log events. Default is true. Set to false to disable logging.