English | 中文
Proxy Discord
conversations for Coze-Bot
, enabling API requests to the GPT4 model with features like 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 Site (Must-read tutorial)
🐞CDP Project - Discussion Group (Discussion)
📢CDP Project - Notification Channel (Notifications)
Features (The project's features are now stable, updates will not be frequent, feel free to raise an issue if you find bugs!)
- Perfectly compatible with
NextChat
,one-api
,LobeChat
and other conversation panels. - Perfect support for conversation isolation.
- Conversation interface supports streaming responses.
- Supports creating
discord
categories/channels/threads. - Supports conversation interface 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
) (following theGPT4V
interface request format [ supportsurl
orbase64
])(supports specifyingdiscord-channel
). - Supports
dall-e-3
text-to-image interface aligned withopenai
(v1/images/generations
). - Supports daily
9 AM
scheduled tasks to keep the bot active. - Supports configuring multiple discord user
Authorization
(environment variableUSER_AUTHORIZATION
) for request load balancing (currently each discord user has a 24-hour limit on coze-bot calls, configure multiple users to stack request counts and balance load). - 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 select
Copy Server ID (GUILD_ID)
and record it, create a default channel in this server, right-click this channel to selectCopy Channel ID (CHANNEL_ID)
and record it. - Open Discord Developer Portal and log in.
- Create a new application-Bot, i.e.,
COZE-BOT
, and record its uniquetoken
andid (COZE_BOT_ID)
, this bot will be managed by coze. - Create a new application-Bot, i.e.,
CDP-BOT
, and record its uniquetoken (BOT_TOKEN)
, this bot will listen for discord messages. - Grant corresponding permissions (
Administrator
) to both bots and invite them to the created discord server (the 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 developer tools-Network
, getAuthorization (USER_AUTHORIZATION)
from the header of this interface and record it. - Open Coze's official website, create and configure a bot (note
Auto-Suggestion
should beDefault/on
(usually no need to change)). - After configuration, choose to publish to discord, fill in the
token
ofCOZE-BOT
, after publishing, you can seeCOZE-BOT
online and can be used with @ in the discord server. - Start configuring environment variables and deploy this project using the recorded parameters.
- Visit 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 already set up that you can use: NextChat
Fill in BaseURL
(ip:port/domain) and 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 modify to your discord user's authorization key (multiple keys separated by commas)
- BOT_TOKEN=MTE5OT************UrUWNbG63w # Must modify to the listening bot's token
- GUILD_ID=11************96 # Must modify to the server ID where both bots are located
- COZE_BOT_ID=11************97 # Must modify to the bot ID managed by coze
- CHANNEL_ID=11************94 # [Optional] Default channel - (currently this parameter is only used to keep the bot active)
- PROXY_SECRET=123456 # [Optional] API key - modify this line to the value used for request header verification (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, try using the GitHub Docker image by replacing deanxv/coze-discord-proxy
with ghcr.io/deanxv/coze-discord-proxy
.
Deploy to 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, the variables USER_AUTHORIZATION
, BOT_TOKEN
, GUILD_ID
, COZE_BOT_ID
, PROXY_SECRET
, CHANNEL_ID
must also be replaced!
Or manually deploy:
-
First fork a copy of the code.
-
Enter Zeabur, log in with GitHub, go to the console.
-
In Service -> Add Service, choose Git (authorize first if it's your first time), select the repository you forked.
-
Deployment will automatically start, cancel it first.
-
Add environment variables
USER_AUTHORIZATION:MTA5OTg5N************uIfytxUgJfmaXUBHVI
Authorization key for discord users initiating messages (separated by commas)BOT_TOKEN:MTE5OTk************WNbG63w
Token for the bot listening to 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 - (currently this parameter is only used to keep the bot active)PROXY_SECRET:123456
[Optional] API key - modify this line to the value used for request header verification (separated by commas) (similar to the openai-API-KEY)
Save.
- Choose Redeploy.
Deploy to Render
Render provides 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 discord users initiating messages (separated by commas)BOT_TOKEN=MTE5OTk2************rUWNbG63w
Token for the bot 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, default is 7077SWAGGER_ENABLE=1
[Optional] Enable Swagger API documentation [0: No; 1: Yes] (default is 1)ONLY_OPENAI_API=0
[Optional] Expose only interfaces aligned with openai [0: No; 1: Yes] (default is 0)CHANNEL_ID=11************24
[Optional] Default channel - (currently this parameter is only used to keep the bot active)PROXY_SECRET=123456
[Optional] API key - modify this line to the value used for request header verification (separated by commas) (similar to the openai-API-KEY), recommended to use this environment variableDEFAULT_CHANNEL_ENABLE=0
[Optional] Enable default channel [0: No; 1: Yes] (default is 0) If enabled, each conversation will occur in the default channel, session isolation will be ineffective, not recommended to use this environment variableALL_DIALOG_RECORD_ENABLE=1
[Optional] Enable full context [0: No; 1: Yes] (default is 1) If disabled, each conversation will only send the lastcontent
inmessages
whererole
isuser
, not recommended to use this environment variableCHANNEL_AUTO_DEL_TIME=5
[Optional] Channel auto-delete time (seconds) This parameter is for automatically deleting the channel after each conversation (default is 5s), if set to 0 then it will not delete, not recommended to use this environment variableCOZE_BOT_STAY_ACTIVE_ENABLE=1
[Optional] Enable daily9 AM
task to keep coze-bot active [0: No; 1: Yes] (default is 1), not recommended to use this environment variableREQUEST_OUT_TIME=60
[Optional] Non-stream response timeout for conversation interface, not recommended to use this environment variableSTREAM_REQUEST_OUT_TIME=60
[Optional] Stream response timeout for each stream return in conversation interface, not recommended 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] Discord user agent, using your own might help prevent being banned, if not set, defaults to the author's, 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
related 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 used)PROXY_URL=http://127.0.0.1:10801
[Optional] Proxy (supports http only)
- Before deployment, create a
data/config/bot_config.json
file in the same directory as thedocker
/docker-compose
deployment - Write the
json
file,bot_config.json
format as follows
[
{
"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) (if the model in the request does not match any 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) (currently 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, the bot will be matched through the [request key] carried in the request header and the [
model
] in the request body. If multiple matches are found, one will be randomly selected. 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 users Authorization
(refer to Environment Variables USER_AUTHORIZATION
) or configure multiple bots to stack request counts and balance load.
Q: How should I configure for high concurrency?
A: First, configure multiple bots to serve as response bots. Secondly, prepare multiple discord accounts to serve as request load and invite them into the same server, obtain the 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: An aggregation of Openai, Alibaba Cloud, Baidu Intelligent Cloud, Qiniu Cloud, and other open platforms, providing content audit services aligned with openai
request formats.
Open source is not easy, if you refer to this project or base your project on it, could you please mention 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