1.0.2 • Published 12 months ago

discord-chatgpt-lib v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

discord-chatgpt-lib

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.

Installation

To install the library, use the following command:

npm install discord-chatgpt-lib

Usage

To use the discord-chatgpt-lib library, follow these steps:

  1. 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);
  1. Start the bot:

    bot.start();
  1. Replace YOUR_DISCORD_BOT_TOKEN with your actual Discord bot token and YOUR_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.
  2. Run your Node.js application:

     node index.js
  3. Your Discord bot is now running and ready to respond to messages in the specified channel(s) using ChatGPT.

Parameters

The DiscordChatGPT constructor accepts the following parameters:

token (required): Your Discord bot token.

apiKey (required): Your OpenAI API key.

options (optional): An object containing additional configuration options.

  1. channelId (optional): The ID of the channel to listen to. If provided, the bot will only respond to messages in that channel.

  2. channelName (optional): The name of the channel to listen to. If provided, the bot will only respond to messages in that channel.

  3. messageToSend (optional): The message format to be sent in the channel. The string {response} will be replaced with ChatGPT's response. Default is '{response}'.
  4. logger (optional): A boolean value indicating whether the bot should log events. Default is true. Set to false to disable logging.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.

Important

Currently this version uses discord.js v13. Will update it to discord.js v14 afterwards.

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago