中文 | English
Act as a proxy for the Discord conversation Coze-Bot, implementing the GPT-4 model request in the form of an API, providing functionalities such as dialogue, text-to-image, image-to-text, and knowledge base retrieval
If you find it interesting, don't forget to hit the 🌟
📄CDP Project Documentation Site(Under Completion)
🐞CDP Project-Discussion Group(Detailed tutorial in the group)
📢CDP Project-Notification Channel(Detailed tutorial in the channel)
- Perfectly adapts to dialogue panels such as
NextChat
,one-api
,LobeChat
. - Perfectly supports dialogue isolation.
- Dialogue interface supports streaming return.
- Supports creating
discord
category/channel/thread. - Supports the dialogue interface aligned with
openai
(v1/chat/completions
) (also supportsdall-e-3
text-to-image) (supports specifyingdiscord-channel
). - Supports the picture-to-text/image-to-image/file-to-text interface aligned with
openai
(v1/chat/completions
) (according to the request format ofGPT4V
interface [supportsurl
orbase64
]) (supports specifyingdiscord-channel
). - Supports the
dall-e-3
text-to-image interface aligned withopenai
(v1/images/generations
). - Supports the daily
9
o'clock scheduled task to automatically activate the bot. - Supports configuring multiple discord user
Authorization
(environment variableUSER_AUTHORIZATION
) for request load balancing (Currently each discord user calling coze-bot has a limit within 24h, you can configure multiple users to achieve superimposed request times and request load balancing). - Supports configuring multiple coze bots for response load balancing (specified by
PROXY_SECRET
/model
) For details, see Advanced Configuration.
http://<ip>:<port>/swagger/index.html
- Open Discord official website, after logging in, click on Settings-Advanced Settings-Developer Mode-Turn On.
- Create a discord server, right-click on this server to select
Copy Server ID (GUILD_ID)
and record it, create a default channel in this server, right-click on this channel to selectCopy Channel ID (CHANNEL_ID)
and record it. - Open Discord Developer Platform and log in.
- Create a new application-Bot, which is
COZE-BOT
, and record thetoken
andid (COZE_BOT_ID)
specific to this bot. This bot will be the bot to be managed by coze. - Create a new application-Bot, which is
CDP-BOT
, and record thetoken (BOT_TOKEN)
specific to this bot. This bot is the bot that listens to discord messages. - Both bots open corresponding permissions (
Administrator
) and invite them into the created discord server (the process is not detailed here). - Open Discord official website, enter the server, press F12 to open the developer tool, send a message in any channel, find the request
https://discord.com/api/v9/channels/1206*******703/messages
in Developer Tools-Network
, getAuthorization(USER_AUTHORIZATION)
from the header of this interface and record it. - Open Coze official website to create a bot and make personalized settings (note
Auto-Suggestion
isDefault/on
(default does not need to be changed)). - After the configuration is completed, choose to publish to discord, fill in the
token
ofCOZE-BOT
, after the publication is completed, you can seeCOZE-BOT
online and can be used in the discord server. - Use the parameters recorded above to start configuring [environment variables](#Environment Variables)and deploy this project.
- Visit the API documentation address, you can start debugging or integrating other projects.
Fill in the interface address (ip:port/domain) and API-Key (PROXY_SECRET
), and the others can be filled in and selected at will.
If you haven't set up the NextChat panel yourself, here is one that has been set up and can be used NextChat
Fill in BaseURL
(ip:port/domain) and Secret Key (PROXY_SECRET
), and the others can be filled in and selected at will.
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************uIfytxUgJfmaXUBHVI # Must be modified to our discord user's authorization key (multiple please separate by ,)
- BOT_TOKEN=MTE5OTk2************wUrUWNbG63w # Must be modified to the Bot-Token that listens to messages
- GUILD_ID=11************96 # Must be modified to the server ID where the two robots are located
- COZE_BOT_ID=11************97 # Must be modified to the robot ID managed by coze
- CHANNEL_ID=11************24 # [Optional] Default channel-(This parameter is only used to activate the robot in the current version)
- PROXY_SECRET=123456 # [Optional] Interface key-Modify this line to the value of the request header check (multiple please separate by ,)
- 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
Where USER_AUTHORIZATION
,BOT_TOKEN
,GUILD_ID
,COZE_BOT_ID
,PROXY_SECRET
,CHANNEL_ID
are replaced with your own.
If the above image cannot be pulled, you can try using GitHub's Docker image, just replace the above deanxv/coze-discord-proxy
with ghcr.io/deanxv/coze-discord-proxy
.
Deploy to Zeabur
Zeabur's servers are abroad, automatically solving the network problem, and the free quota is also sufficient for personal use
Click one-click deployment:
After one-click deployment, USER_AUTHORIZATION
,BOT_TOKEN
,GUILD_ID
,COZE_BOT_ID
,PROXY_SECRET
,CHANNEL_ID
variables also need to be replaced!
Or manual deployment:
-
First fork a copy of the code.
-
Enter Zeabur, log in with github, and enter the console.
-
In Service -> Add Service, choose Git (the first time you use it, you need to authorize first), choose the repository you forked.
-
Deploy will start automatically, cancel first.
-
Add environment variables
USER_AUTHORIZATION:MTA5OTg5N************uIfytxUgJfmaXUBHVI
The authorization key of the discord user who actively sends messages (multiple please separate by ,)BOT_TOKEN:MTE5OTk2************rwUrUWNbG63w
Bot-Token that listens to messagesGUILD_ID:11************96
Server ID where the two robots are locatedCOZE_BOT_ID:11************97
Robot ID managed by cozeCHANNEL_ID:11************24
# [Optional] Default channel-(This parameter is only used to activate the robot in the current version)PROXY_SECRET:123456
[Optional] Interface key-Modify this line to the value of the request header check (multiple please separate by ,) (Same usage as openai-API-KEY)
Save.
- Choose Redeploy.
Deploy to Render
Render provides a free quota, and the quota can be further increased after binding the card
Render can directly deploy docker images, no need to fork the repository: Render
USER_AUTHORIZATION=MTA5OTg5N************uIfytxUgJfmaXUBHVI
- Authorization keys of the Discord users who initiate messages (for multiple keys, please separate with commas)BOT_TOKEN=MTE5OTk2************rUWNbG63w
- Bot-Token for listening to messagesGUILD_ID=11************96
- Server ID where all Bots are locatedCOZE_BOT_ID=11************97
- Bot-ID managed by CozePORT=7077
- [Optional] Port number, default is 7077SWAGGER_ENABLE=1
- [Optional] Enable Swagger API documentation [0: No; 1: Yes] (default is 1)ONLY_OPENAI_API=0
- [Optional] Expose only those APIs that align 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] Interface key - modify this line to validate the request header value (for multiple keys, please separate with commas) (consistent with the usage of OpenAI-API-KEY), recommended to use this environment variableDEFAULT_CHANNEL_ENABLE=0
- [Optional] Enable default channel [0: No; 1: Yes] (default is 0). Once enabled, each conversation will take place in the default channel, session isolation will be ineffective, not recommended to use this environment variableALL_DIALOG_RECORD_ENABLE=1
- [Optional] Enable full context recording [0: No; 1: Yes] (default is 1). If turned off, only the lastcontent
withrole
asuser
inmessages
will be sent each time, not recommended to use this environment variableCHANNEL_AUTO_DEL_TIME=5
- [Optional] Automatic channel deletion time (seconds). This parameter determines the time to automatically delete the channel after each conversation (default is 5s). If set to 0, the channel will not be deleted, not recommended to use this environment variableCOZE_BOT_STAY_ACTIVE_ENABLE=1
- [Optional] Enable the daily task of keeping the Coze-bot active at9
o'clock [0: No; 1: Yes] (default is 1), not recommended to use this environment variableREQUEST_OUT_TIME=60
- [Optional] Request timeout for non-stream response in dialogue interface, not recommended to use this environment variableSTREAM_REQUEST_OUT_TIME=60
- [Optional] Stream return timeout for each stream response in dialogue interface, not recommended to use this environment variableREQUEST_RATE_LIMIT=60
- [Optional] Limit the request rate of single IP per minute, 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] Discord user agent. Using your own may effectively prevent being banned. If not set, the author's default will be used. It is recommended to use this environment variable.NOTIFY_TELEGRAM_BOT_TOKEN=6232***********Niz9c
[Optional] Functions as the token for the TelegramBot notification (Notification events include: 1. Unavailability of user_authorization; 2. Risk control trigger by the BOT associated with BOT_TOKEN)NOTIFY_TELEGRAM_USER_ID=10******35
[Optional] The Telegram-Bot linked with NOTIFY_TELEGRAM_BOT_TOKEN forwards notifications to the Telegram-User associated with this variable (This variable must not be empty when NOTIFY_TELEGRAM_BOT_TOKEN is populated)PROXY_URL=http://127.0.0.1:10801
- [Optional] Proxy (only supports http)
- Before deployment, create a
data/config/bot_config.json
file in the same directory as thedocker
/docker-compose
deployment - Write this
json
file, the format ofbot_config.json
is as follows
[
{
"proxySecret": "123", // Interface request key (PROXY_SECRET) (Note: This key exists in the environment variable PROXY_SECRET so that this Bot can be matched!)
"cozeBotId": "12***************31", // coze-managed bot ID
"model": ["gpt-3.5","gpt-3.5-16k"], // Model name (array format) (corresponds to the model in the request parameter, if the model in the request does not match this json, it will throw an exception)
"channelId": "12***************56" // [Optional] discord channel ID (the robot must be in the server of this channel) (in the current version, this parameter is only used to activate the robot)
},
{
"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 there is this json configuration, it will match the
cozeBotId
in this configuration through the [request key] carried in the request header +model
in the request body. If multiple matches are found, one will be randomly selected. The configuration is very flexible and can be configured according to your own needs.
The service deployed on a third-party platform (such as: zeabur
) needs to [configure multiple bots]Please refer to issue#30
The current version of coze has implemented identification for each Discord user, and there is a usage limit for each user per different model on Discord, specifically as follows:
GPT-4 Turbo (128k) - 50 times/day
GPT-4 (8k) - 100 times/day
GPT-3.5 (16k) - 500 times/day
Multiple Discord user Authorization
can be configured (refer to the environment variable USER_AUTHORIZATION
) to achieve cumulative request times and load balancing for requests.
Q: How to configure when the concurrency is high?
A: First, configure multiple bots for the service to serve as the response bot load, and then prepare multiple discord accounts to serve as the request load and invite them into the same server, get the Authorization
of each account and separate them with English commas. Configure in the environment variable USER_AUTHORIZATION
, at this time each request will take out one from multiple discord accounts to initiate a conversation, effectively achieving load balancing.
Open source is not easy, if you refer to this project or based on this project for secondary development, can you bother to mark this project in your project documentation? Thank you! ♥♥♥
Java: https://github.com/oddfar/coze-discord (Currently unavailable)
Coze Official Website : https://www.coze.com
Discord Development Address : https://discord.com/developers/applications