# discord-chatgpt-lib

> A library for creating ChatGPT-powered Discord bots.

Latest version **1.0.2** (published 2023-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install discord-chatgpt-lib
pnpm add discord-chatgpt-lib
yarn add discord-chatgpt-lib
bun add discord-chatgpt-lib
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-05-19 |
| First published | 2023-05-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | dope_0001 |
| Maintainers | dope_0001 |
| Keywords | discord, chatgpt, library |

## Links

- npm: https://www.npmjs.com/package/discord-chatgpt-lib
- npm.io page: https://npm.io/package/discord-chatgpt-lib

## Dependencies (2)

- [openai](https://npm.io/package/openai.md) ^3.2.1
- [discord.js](https://npm.io/package/discord.js.md) ^13.16.0

## Recent versions

- 1.0.2 (latest) — 2023-05-19
- 1.0.1 — 2023-05-19
- 1.0.0 — 2023-05-19

## README

# 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:

```shell
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 DiscordChatGPT = require('discord-chatgpt-lib');

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);
  ```

2. Start the bot:

   ```
   bot.start();
   ```



3. 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.
4. Run your Node.js application:

   ```
    node index.js
    ```
5. 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.

---
_Source: https://npm.io/package/discord-chatgpt-lib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
