English | 中文
Proxies Discord
conversations to Coze-Bot
, enabling API requests to the GPT4 model, offering functionalities such as conversation, text-to-image, image-to-text, and knowledge base retrieval.
If you find this interesting, don't forget to give it a 🌟
📄CDP Project Documentation (Essential Tutorial)
🐞CDP Project - Discussion Group (Discussion)
📢CDP Project - Notification Channel (Notifications)
Features (The project features are now stable, iterations will not be frequent, feel free to raise an issue if you find bugs!)
- Perfectly compatible with
NextChat
,one-api
,LobeChat
, and other chat panels. - Fully supports conversation isolation.
- Conversation API supports streaming responses.
- Supports creating
discord
categories/channels/threads. - Supports conversation interfaces aligned with
openai
(v1/chat/completions
) (also supportsdall-e-3
text-to-image) (supports specifyingdiscord-channel
). - Supports image-to-text/image-to-image/file-to-text interfaces aligned with
openai
(v1/chat/completions
) (using theGPT4V
request format [supportsurl
orbase64
]) (supports specifyingdiscord-channel
). - Supports
dall-e-3
text-to-image interface aligned withopenai
(v1/images/generations
). - Supports daily tasks at
9
AM to keep the bot active. - Supports configuring multiple Discord user
Authorization
(environment variableUSER_AUTHORIZATION
) for request load balancing (currently, each Discord user's use of coze-bot is limited to 24 hours, configure multiple users to stack request limits and load balance). - Supports configuring multiple coze bots for response load balancing (specified through
PROXY_SECRET
/model
) see Advanced Configuration for details.
http://<ip>:<port>/swagger/index.html
- Open Discord's official website, log in, click settings -> advanced settings -> developer mode -> turn on.
- Create a Discord server, right-click this server to choose
Copy Server ID (GUILD_ID)
and record it, create a default channel in this server, right-click this channel to chooseCopy Channel ID (CHANNEL_ID)
and record it. - Open Discord Developer Portal and log in.
- Create a new application -> Bot named
COZE-BOT
, and record its exclusivetoken
andid (COZE_BOT_ID)
, this bot will be managed by coze. - Create a new application -> Bot named
CDP-BOT
, and record its exclusivetoken (BOT_TOKEN)
, this bot will listen for Discord messages. - Grant appropriate permissions (
Administrator
) to both bots and invite them to the created Discord server (this process is not described here). - Open Discord's official website, enter the server, press F12 to open developer tools, send a message in any channel, find the request
https://discord.com/api/v9/channels/1206*******703/messages
in the developer tools-Network
, getAuthorization (USER_AUTHORIZATION)
from the header of this interface and record it. - Open coze's official website to create a bot and configure it (note
Auto-Suggestion
should beDefault/on
(usually no need to change)). - After configuration, choose to publish to Discord, fill in the
COZE-BOT
'stoken
, after publishing, you can seeCOZE-BOT
online in the Discord server and can be used with @. - Use the recorded parameters to start configuring environment variables and deploy this project.
- Access the API documentation address, and you can start debugging or integrating other projects.
Fill in the interface address (ip:port/domain) and API-Key (PROXY_SECRET
), other fields are optional.
If you haven't set up a NextChat panel yourself, here's one that's already set up and available for use: NextChat
Fill in BaseURL
(ip:port/domain) and the key (PROXY_SECRET
), other fields are optional.
docker-compose pull && docker-compose up -d
version: '3.4'
services:
coze-discord-proxy:
image: deanxv/coze-discord-proxy:latest
container_name: coze-discord-proxy
restart: always
ports:
- "7077:7077"
volumes:
- ./data:/app/coze-discord-proxy/data
environment:
- USER_AUTHORIZATION=MTA5OTg5N************aXUBHVI # Must be modified to your Discord user's authorization key (multiple keys separated by commas)
- BOT_TOKEN=MTE5OT************UrUWNbG63w # Must be modified to the listening bot's token
- GUILD_ID=11************96 # Must be modified to the server ID where both bots are located
- COZE_BOT_ID=11************97 # Must be modified to the bot ID managed by coze
- CHANNEL_ID=11************94 # [Optional] Default channel - (in the current version, this parameter is only used to keep the bot active)
- PROXY_SECRET=123456 # [Optional] API key - modify this line to the value checked in the request header (multiple keys separated by commas)
- TZ=Asia/Shanghai
docker run --name coze-discord-proxy -d --restart always \
-p 7077:7077 \
-v $(pwd)/data:/app/coze-discord-proxy/data \
-e USER_AUTHORIZATION="MTA5OTg5N************uIfytxUgJfmaXUBHVI" \
-e BOT_TOKEN="MTE5OTk2************rUWNbG63w" \
-e GUILD_ID="11************96" \
-e COZE_BOT_ID="11************97" \
-e PROXY_SECRET="123456" \
-e CHANNEL_ID="11************24" \
-e TZ=Asia/Shanghai \
deanxv/coze-discord-proxy
Modify USER_AUTHORIZATION
, BOT_TOKEN
, GUILD_ID
, COZE_BOT_ID
, PROXY_SECRET
, CHANNEL_ID
to your own values.
If the above image cannot be pulled, you may try using the GitHub Docker image by replacing deanxv/coze-discord-proxy
with ghcr.io/deanxv/coze-discord-proxy
.
Deploying on Zeabur
Zeabur's servers are located abroad, automatically solving network issues, and the free tier is sufficient for personal use.
Click to deploy:
After one-click deployment, variables like USER_AUTHORIZATION
, BOT_TOKEN
, GUILD_ID
, COZE_BOT_ID
, PROXY_SECRET
, CHANNEL_ID
need to be replaced!
Or manually deploy:
-
First fork a copy of the code.
-
Enter Zeabur, log in with GitHub, and go to the console.
-
In Service -> Add Service, select Git (authorization is required for the first use), choose the repository you forked.
-
Deployment will automatically start, cancel it first.
-
Add environment variables:
USER_AUTHORIZATION:MTA5OTg5N************uIfytxUgJfmaXUBHVI
Authorization key for the Discord user initiating messages (separate multiple keys with commas)BOT_TOKEN:MTE5OTk************WNbG63w
Token for the bot that listens for messagesGUILD_ID:11************96
Server ID where both bots are locatedCOZE_BOT_ID:11************97
Bot ID managed by cozeCHANNEL_ID:11************24
[Optional] Default channel - (in the current version, this parameter is only used to keep the bot active)PROXY_SECRET:123456
[Optional] API key - modify this line to the value checked in the request header (separate multiple keys with commas) (used in the same way as the openai API-KEY)
Save.
- Choose Redeploy.
Deploying on Render
Render offers a free tier, and linking a card can further increase the limit.
Render can directly deploy Docker images without needing to fork the repository: Render
USER_AUTHORIZATION=MTA5OTg5N************uIfytxUgJfmaXUBHVI
Authorization key for the Discord user initiating messages (separate multiple keys with commas)BOT_TOKEN=MTE5OTk2************rUWNbG63w
Token for the bot that listens for messagesGUILD_ID=11************96
Server ID where all bots are locatedCOZE_BOT_ID=11************97
Bot ID managed by cozePORT=7077
[Optional] Port, default is 7077SWAGGER_ENABLE=1
[Optional] Whether to enable Swagger API documentation [0: No; 1: Yes] (default is 1)ONLY_OPENAI_API=0
[Optional] Whether to expose only the interfaces aligned with OpenAI [0: No; 1: Yes] (default is 0)CHANNEL_ID=11************24
[Optional] Default channel - (in the current version, this parameter is only used to keep the bot active)PROXY_SECRET=123456
[Optional] API key - modify this line to the value checked in the request header (separate multiple keys with commas) (used in the same way as the openai API-KEY), it is recommended to use this environment variableDEFAULT_CHANNEL_ENABLE=0
[Optional] Whether to enable the default channel [0: No; 1: Yes] (default is 0) If enabled, every conversation will take place in the default channel, session isolation will be ineffective, it is recommended not to use this environment variableALL_DIALOG_RECORD_ENABLE=1
[Optional] Whether to enable full context recording [0: No; 1: Yes] (default is 1) If disabled, each conversation will only send the lastcontent
ofrole
asuser
inmessages
, it is recommended not to use this environment variableCHANNEL_AUTO_DEL_TIME=5
[Optional] Auto-delete time for channels (seconds) This parameter sets the time to automatically delete the channel after each conversation (default is 5s), 0 means no deletion, it is recommended not to use this environment variableCOZE_BOT_STAY_ACTIVE_ENABLE=1
[Optional] Whether to enable a daily task at9
AM to keep the coze-bot active [0: No; 1: Yes] (default is 1), it is recommended not to use this environment variableREQUEST_OUT_TIME=60
[Optional] Request timeout for non-stream response under conversation interface, it is recommended not to use this environment variableSTREAM_REQUEST_OUT_TIME=60
[Optional] Timeout for each stream return under stream response of conversation interface, it is recommended not to use this environment variableREQUEST_RATE_LIMIT=60
[Optional] Request rate limit per minute per IP, default: 60 requests/minUSER_AGENT=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
[Optional] User agent for Discord users, using your own might effectively prevent being banned, if not set, the default is the author's, it is recommended to use this environment variableNOTIFY_TELEGRAM_BOT_TOKEN=6232***********Niz9c
[Optional] Token for a Telegram Bot used for notifications (notification events: 1. No availableuser_authorization
; 2.BOT_TOKEN
associated BOT triggers risk control)NOTIFY_TELEGRAM_USER_ID=10******35
[Optional] TheTelegram-Bot
associated withNOTIFY_TELEGRAM_BOT_TOKEN
will push to theTelegram-User
associated with this variable (NOTIFY_TELEGRAM_BOT_TOKEN
must not be empty if this variable is set)PROXY_URL=http://127.0.0.1:10801
[Optional] Proxy (supports http only)
- Before deploying, create a
data/config/bot_config.json
file in the same directory as yourdocker
/docker-compose
deployment. - Write the following
json
file,bot_config.json
format as shown below:
[
{
"proxySecret": "123", // API request key (PROXY_SECRET) (Note: this key must exist in the environment variable PROXY_SECRET for this bot to be matched!)
"cozeBotId": "12***************31", // Bot ID managed by coze
"model": ["gpt-3.5","gpt-3.5-16k"], // Model names (array format) (matches the `model` in the request body, if the model in the request is not matched in this json, an exception will be thrown)
"channelId": "12***************56" // [Optional] Discord channel ID (the bot must be in the server where this channel is located) (in the current version, this parameter is only used to keep the bot active)
},
{
"proxySecret": "456",
"cozeBotId": "12***************64",
"model": ["gpt-4","gpt-4-16k"],
"channelId": "12***************78"
},
{
"proxySecret": "789",
"cozeBotId": "12***************12",
"model": ["dall-e-3"],
"channelId": "12***************24"
}
]
- Restart the service.
When this json configuration is present, it will match the
cozeBotId
through the request header's [request key] + request body's [model
]. If multiple matches are found, one will be selected at random. The configuration is very flexible and can be adjusted according to your needs.
For services deployed on third-party platforms (such as zeabur
) that need [configuring multiple bots], please refer to issue#30.
Current details of coze's free and paid subscriptions: https://www.coze.com/docs/guides/subscription?_lang=en
You can configure multiple Discord user Authorization
(refer to Environment Variables USER_AUTHORIZATION
) or configure multiple bots to stack request limits and achieve load balancing.
Q: How should I configure the service for high concurrency?
A: First, configure multiple bots to be used as response bots for load balancing. Next, prepare multiple Discord accounts for request load balancing and invite them to the same server. Obtain Authorization
for each account, separate them with commas, and configure them in the environment variable USER_AUTHORIZATION
. Each request will then pick one Discord account to initiate the conversation, effectively achieving load balancing.
GPT-Content-Audit: Aggregates platforms like OpenAI, Alibaba Cloud, Baidu Intelligent Cloud, Qiniu Cloud, etc., providing content moderation services aligned with OpenAI's request format.
Open source is challenging; if you refer to this project or base your project on it, could you please credit this project in your project documentation? Thank you!
Java: https://github.com/oddfar/coze-discord (currently unavailable