Skip to content

Repository files navigation

⚡ Zai Multi-Platform APIs & AI Discord Bot Gateway

A lightweight, modular, self-hosted OpenAI-compatible API Gateway and AI Discord Bot built with Express.js and Discord.js.

Drop any module file into the api/ folder and it appears instantly on the dynamic interactive documentation site (/docs) — no config files or rebuilds required!


📸 Discord Bot Preview

Discord Bot Preview


👨‍💻 Developer Information & Contact


🌟 Key Features

  • 🤖 Native AI Discord Bot (discord_bot.js): Out-of-the-box Discord bot with streaming AI responses, model selection, typing indicators, and multi-message splitting.
  • OpenAI-Compatible Gateway: /v1/chat/completions and /v1/models endpoints compatible with standard OpenAI SDKs and tools.
  • 🔑 Automatic Token Load Balancer: Dynamically rotates zAI & Discord tokens for maximum reliability.
  • 📦 Dynamic Module Auto-Loader: Drop a .js module file anywhere inside api/ (subfolders supported: api/ai/, api/tools/, api/info/) and the server automatically registers the endpoint on startup.
  • 🌐 Interactive Documentation (/docs): Dynamic OpenAPI-style UI with live search, category filtering, parameter preview, and a built-in "Try It Out" API runner.
  • 🐳 Docker Ready: Preconfigured Dockerfile and docker-compose.yml for instant deployment.

📁 Project Structure

.
├── api/ # Dynamic API modules
│ ├── ai/
│ │ ├── zai_chat.js # /v1/chat/completions (OpenAI Compatible)
│ │ └── models.js # /v1/models
│ ├── tools/
│ │ └── token_manager.js # /api/tools/token-status
│ └── info/
│ └── ping.js # /api/info/ping
├── core/ # Server core & middleware
├── json/ # Configuration & tokens storage
├── png/ # Setup screenshots & documentation images
│ ├── discord_bot_preview.png
│ └── get_discord_token.png
├── discord_bot.js # Ready-to-run AI Discord Bot
├── index.js # Gateway entry point
├── package.json
└── README.md

🚀 Quick Start Guide

1. Install Dependencies

npm install

2. Start API Gateway Server

npm start

For development mode (auto-reload on Node 18+):

npm run dev

The server starts on port 5000 by default.

  • Landing Page: http://localhost:5000
  • Interactive Docs: http://localhost:5000/docs
  • Management Console: http://localhost:5000/manage
  • OpenAI Base: http://localhost:5000/v1

🔑 How to Get Your Discord User Token (For zAI Authentication)

Get Discord Token

  1. Open discord.com/app on Chrome / Edge / Brave and log into your Discord account.
  2. Press F12 to open Developer Tools.
  3. Go to the Console tab, paste the following command, and press Enter:
    window.webpackChunkdiscord_app.push([[Math.random()],{},e=>{for(constmofObject.values(e.c))if(m?.exports?.default?.getToken!==undefined)console.log(m.exports.default.getToken())}])
  4. Copy your user token.
  5. Open http://localhost:5000/manage in your browser and add the token to the system.

🤖 Complete Setup Guide: Running the AI Discord Bot (discord_bot.js)

Follow these simple steps to run your AI Discord Bot:

Step 1: Create a Bot on Discord Developer Portal

  1. Go to Discord Developer Portal.
  2. Click New Application, enter a name (e.g. zAI Assistant), and click Create.
  3. Go to the Bot tab on the left menu:
    • Click Reset Token (or Add Bot) and copy your Bot Token.
  4. CRITICAL STEP - Enable Privileged Gateway Intents:
    • Scroll down to Privileged Gateway Intents.
    • Enable MESSAGE CONTENT INTENT 🟢.
    • Click Save Changes.

Step 2: Invite the Bot to Your Discord Server

  1. Go to OAuth2 -> URL Generator.
  2. Under Scopes, select bot.
  3. Under Bot Permissions, select:
    • Send Messages
    • Read Message History
    • Embed Links
  4. Copy the generated URL, paste it into your browser, select your server, and click Authorize.

Step 3: Run the Discord Bot

Make sure the API Gateway (npm start) is running, then open a terminal and run:

node discord_bot.js YOUR_DISCORD_BOT_TOKEN

Or set the environment variable:

export DISCORD_BOT_TOKEN="YOUR_DISCORD_BOT_TOKEN"
node discord_bot.js

Step 4: Interact with Your Bot in Discord

In any channel on your Discord server:

  • !ai <prompt> ➜ Ask the bot any question (e.g., !ai Write a python quicksort function).
  • @zAI Assistant <prompt> ➜ Mention the bot directly.
  • !models ➜ List available AI models.
  • !ping ➜ Check bot latency.

📄 API Endpoints Reference

EndpointMethodDescription
/v1/chat/completionsPOSTOpenAI-compatible chat completions
/v1/modelsGETList all supported AI models
/api/info/pingGETSystem health check & uptime
/api/tools/token-statusGETActive token count & rotation status
/docsGETInteractive OpenAPI documentation UI

🐳 Docker Deployment

docker-compose up -d

📄 License

This project is for educational and research purposes only.

About

Unlim-ited useNano Banana,Nano Banana Pro,Gemini 3 Pro Preview,

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages