https://github.com/joesiu/discord-chatbot
Another Discord chatbot that supports poe.com's ChatGPT bots and Hugging Face models
https://github.com/joesiu/discord-chatbot
chatbot chatgpt discord discord-bot discord-py gpt hugging-face huggingface
Last synced: about 1 year ago
JSON representation
Another Discord chatbot that supports poe.com's ChatGPT bots and Hugging Face models
- Host: GitHub
- URL: https://github.com/joesiu/discord-chatbot
- Owner: JoeSiu
- Created: 2023-04-05T19:29:10.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-05-31T15:57:50.000Z (about 2 years ago)
- Last Synced: 2025-04-06T20:47:51.665Z (about 1 year ago)
- Topics: chatbot, chatgpt, discord, discord-bot, discord-py, gpt, hugging-face, huggingface
- Language: Python
- Homepage:
- Size: 91.8 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Discord ChatBot
### Update: As the [Unoffical Poe API](https://github.com/ading2210/poe-api) had been archived and is not working, the Poe bot will not work now.
## Description
The Discord ChatBot is a Python-based chatbot that supports following:
- [Poe](https://poe.com/) bots (via [Unoffical API](https://github.com/ading2210/poe-api)), including `Sage`, `GPT-4`, `Claude+`, `Claude-instant`, `ChatGPT`, etc, as well as custom bots
- All [Hugging Face conversational models](https://huggingface.co/models?pipeline_tag=conversational)
## Demo

## Installation Instructions
To run the Discord ChatBot, follow these steps:
### Setup
1. Clone this repository using Git.
2. Duplicate the `.env.example` file and rename it to `.env`. Replace each key with the corresponding values.
3. Go to [Discord Developer Portal](https://discord.com/developers/applications) and create a new application.
4. Create a bot and copy its token.
5. Paste the token into the `DISCORD_TOKEN` field in the `.env` file.
#### Environment Variables
| Env variables | Description |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DISCORD_TOKEN | Discord token, obtained from [https://discord.com/developers/applications](https://discord.com/developers/applications). |
| POE_TOKEN | Poe token, should be the browser cookie for [https://poe.com](https://poe.com/), refer to [poe-api](https://github.com/ading2210/poe-api) repository for more details. Leave empty if you don't intend to use the Poe bot. |
| POE_MODEL | Default Poe bot (name), e.g., `Sage`, `GPT-4`, `Claude+`, `Claude-instant`, `ChatGPT`, etc. Leave empty if you don't intend to use the Poe bot. |
| POE_PROXY | The default proxy. Leave empty if you don't intend to use the Poe bot or want to skip using a proxy. |
| HUGGING_FACE_TOKEN | Hugging Face token, obtained from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens). Leave empty if you don't intend to use the Hugging Face bot. |
| HUGGING_FACE_MODEL | Default Hugging Face model, refer to [Hugging Face conversational models](https://huggingface.co/models?pipeline_tag=conversational). Leave empty if you don't intend to use the Hugging Face bot. |
| DEBUG | Whether to use debug view. (Only used for Hugging Face chatbot) |
| LOGGING_LEVEL | Console logging level, default to INFO (20) if not provided |
#### Poe
To use the Poe bot, follow the steps below:
1. Refer to [poe-api guide](https://github.com/ading2210/poe-api#finding-your-token) to obtain your token.
2. Update the `POE_TOKEN` field in the `.env` file.
3. Set the `POE_MODEL` field to the desired model (e.g., `ChatGPT`).
4. Optionally, set the `POE_PROXY` field for proxy settings.
#### Hugging Face
To use the Hugging Face bot, follow the steps below:
1. Obtain your Hugging Face API token from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens).
2. Set the `HUGGING_FACE_MODEL` field to the desired model. (Find the model from [https://huggingface.co/models?pipeline_tag=conversational](https://huggingface.co/models?pipeline_tag=conversational), then copy the model name, e.g., `facebook/blenderbot-3B`).
### Run the program
#### CLI
1. Make sure you have [Python 3.10](https://www.python.org/downloads/release/python-3106/) installed.
2. Run `pip install -r requirements.txt` to install the required dependencies, using python virtual environment is recommended.
3. Run `python main.py` to start the bot.
##### Available command arguments
You can also use the following command arguments:
| Arugments | Description | Options |
| ------------------------------ | -------------------------------------------------------- | --------------------- |
| `--bot [str]` | Select the chatbot to use. | `poe`, `hugging-face` |
| `--model [str]` | Select the chatbot model to use. | Depends on bot |
| `--channel-monitor-mode [str]` | Select the channel monitor mode. | `all`, `none` |
| `--enable-name-prefix [bool]` | Enable or disable prefixing user names to chat messages. | `True`, `False` |
#### Docker (Work in Progress)
Make sure you have python and docker installed
1. Make sure you have Docker installed.
2. run `docker-compose build` to build the docker image.
3. run `docker-compose up -d` to start the container.
## Usage
### Discord commands
| Command | Description | Options |
| ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
| `/send [str]` | Send a message to the chatbot. This command can bypass Discord's message limit for non-nitro users and allows messages up to 6000 characters in length. | |
| `/send_to_channel [str]` | Send a message to the chatbot on another channel, useful when multiple chatbots are monitoring the same channel. This command can bypass Discord's message limit for non-nitro users and allows messages up to 6000 characters in length. | |
| `/clear-context` | Clear the current context of the chatbot. | |
| `/get-bot` | Returns the current bot being used. | |
| `/get-available-bot` | Returns the available bots. | |
| `/change-bot [str]` | Changes the current bot being used. If an invalid bot is specified, the available bot names will be shown. | `poe`, `hugging-face` |
| `/reset-bot` | Resets the current bot to the default bot specified in .env. | |
| `/get-model` | Returns the current chatbot model being used. | |
| `/get-available-model` | Returns the current chatbot's available models. | |
| `/change-model [str]` | Changes the current chatbot model being used. If an invalid model is specified, the available model names will be shown. | Depends on the bot |
| `/reset-model` | Resets the current chatbot model to the default model specified in .env. | |
| `/change-token [str]` | Changes the API token for the chatbot. | |
| `/reset-token` | Resets the API token for the chatbot to the default token specified in .env. | |
| `/enable-channel-monitoring` | Enables monitoring of the current channel, will add the current channel to whitelist if `channel-monitor-mode` is set to `none`. | |
| `/disable-channel-monitoring` | Disable monitoring of the current channel. | |
| `/get-channel-whitelist` | Returns the channel whitelist. | |
| `/get-channel-blacklist` | Returns the channel blacklist. | |
| `/get-channel-monitor-mode` | Returns the current monitoring mode. | |
| `/change-channel-monitor-mode [str]` | Changes the current monitoring mode. If an invalid mode is specified, the available modes will be shown. | `all`, `none` |
| `/enable-name-prefix` | Enables prefixing the chat messages with the username or nickname. | |
| `/disable-name-prefix` | Disables prefixing the chat messages with the username or nickname. | |
| `/register-nickname [str]` | Registers or updates a nickname. | |
| `/unregister-nickname` | Unregisters a nickname if it is registered. | |
| `/get-nickname` | Returns the registered nickname if there is one. | |
- You can also use `$ignore` at the beginning of a message to instruct the bot to ignore that message.
- In channel monitor mode, setting it to `all` will cause the bot to reply to messages in all channels, except for those in the blacklist. Setting it to `none` will prevent the bot from replying to messages in any channel, except for those in the whitelist.
- When name prefix is enabled, the bot will automatically add the Discord username or nickname (if registered via the `/register-nickname` command) of the message author to the front of the message. For example, the message `hello` will become `Joe: hello` when sent to the bot. This feature is useful for multi-person conversations, especially when giving the bot a prompt.
- Nicknames, channel whitelist and blacklists are stored inside `config.json` file.
## Limitation
- Currently, the bot has only been tested on a single server and in direct messages.
- The bot is a single instance only, which means that any messages or commands sent in direct messages or different channels will be treated as if they came from the same source.
## Note
- This is just a simple holiday project, might not update in the future. 🙃