CodeX - Dash and API Fixed

This commit is contained in:
RayExo
2026-07-16 11:14:48 +05:30
parent 7c3ef0d5a5
commit a2f113a35f
276 changed files with 4540 additions and 351 deletions

352
README.md
View File

@@ -9,14 +9,20 @@
╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
```
**A feature-rich Discord bot paired with a sleek Next.js dashboard**
[![Python](https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white)](https://python.org)
[![Next.js](https://img.shields.io/badge/Next.js-14+-000000?style=for-the-badge&logo=nextdotjs&logoColor=white)](https://nextjs.org)
[![FastAPI](https://img.shields.io/badge/FastAPI-Backend-009688?style=for-the-badge&logo=fastapi&logoColor=white)](https://fastapi.tiangolo.com)
[![Discord](https://img.shields.io/badge/Discord.py-v2-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discordpy.readthedocs.io)
[![License](https://img.shields.io/badge/License-MIT-red?style=for-the-badge)](LICENSE)
[![Support](https://img.shields.io/badge/Support-discord.gg/codexdev-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/codexdev)
<h3>A feature-rich Discord bot paired with a sleek Next.js dashboard</h3>
<a href="https://nexiohost.in"><img src="https://img.shields.io/badge/⭐%20PREMIUM%20HOSTING-NexioHost-FFD700?style=for-the-badge&labelColor=1a1a2e&color=FFD700&logoColor=FFD700"/></a>
<p>
<a href="https://python.org"><img src="https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white"/></a>
<a href="https://nextjs.org"><img src="https://img.shields.io/badge/Next.js-14+-000000?style=for-the-badge&logo=nextdotjs&logoColor=white"/></a>
<a href="https://fastapi.tiangolo.com"><img src="https://img.shields.io/badge/FastAPI-Backend-009688?style=for-the-badge&logo=fastapi&logoColor=white"/></a>
<a href="https://discordpy.readthedocs.io"><img src="https://img.shields.io/badge/Discord.py-v2-5865F2?style=for-the-badge&logo=discord&logoColor=white"/></a>
</p>
<p>
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-red?style=for-the-badge"/></a>
<a href="https://discord.gg/codexdev"><img src="https://img.shields.io/badge/Discord-Join_Server-5865F2?style=for-the-badge&logo=discord&logoColor=white"/></a>
<a href="https://youtube.com/@CodeXDevs"><img src="https://img.shields.io/badge/YouTube-CodeXDevs-FF0000?style=for-the-badge&logo=youtube&logoColor=white"/></a>
<a href="https://github.com/RayExo"><img src="https://img.shields.io/badge/GitHub-RayExo-181717?style=for-the-badge&logo=github&logoColor=white"/></a>
</p>
</div>
@@ -28,18 +34,21 @@ ZyroX is a fully-featured Discord bot with a modern web dashboard for managing e
```
ZyroX-CV2-With-Dashboard/
├── 🤖 bot/ Python Discord bot + FastAPI backend
│ ├── api/ Dashboard REST API (FastAPI)
│ ├── cogs/ All bot features (commands, events, antinuke, automod…)
│ ├── utils/ Shared utilities (emoji, tools, sync…)
│ ├── assets/ Fonts, backgrounds, GIFs
── CodeX.py Entry point
├── 🤖 bot/ Python Discord bot + FastAPI backend
│ ├── api/ Dashboard REST API (FastAPI)
│ ├── cogs/ All bot features (commands, events, antinuke, automod…)
│ ├── core/ Bot client, context, cog base
│ ├── utils/ Shared utilities (emoji, tools, sync, ngrok tunnel…)
── games/ Standalone game modules
│ ├── assets/ Fonts, backgrounds, GIFs
│ └── CodeX.py Entry point
└── 🌐 dashboard/ Next.js frontend
├── app/ App Router pages
├── components/ Reusable UI components
├── hooks/ Custom React hooks
── lib/ API helpers & utilities
└── 🌐 dashboard/ Next.js frontend
├── app/ App Router pages & API routes
├── components/ Reusable UI components
├── hooks/ Custom React hooks
── lib/ API helpers & utilities
└── types/ TypeScript type definitions
```
---
@@ -51,11 +60,11 @@ ZyroX-CV2-With-Dashboard/
<td width="50%">
**🛡️ Security**
- Antinuke (ban, kick, channel/role flood, webhook abuse…)
- Automod (spam, caps, links, invites, mass mentions, emoji spam)
- Antinuke ban, kick, channel & role flood, webhook abuse, bot adds, prune
- Automod spam, caps, links, invites, mass mentions, emoji spam
- Anti-member update protection
- Whitelist / unwhitelist system
- Emergency mode
- Emergency lockdown mode
</td>
<td width="50%">
@@ -73,9 +82,9 @@ ZyroX-CV2-With-Dashboard/
<td>
**⚙️ Management**
- Moderation (ban, kick, mute, warn, lock…)
- Logging system
- Reaction roles, vanity roles
- Moderation ban, kick, mute, warn, lock, jail, and more
- Full logging system
- Reaction roles, vanity roles, invite tracker
- Tickets, giveaways, verification
- Join-to-create voice channels
@@ -85,9 +94,10 @@ ZyroX-CV2-With-Dashboard/
**🌐 Dashboard**
- Discord OAuth2 login
- Per-server settings management
- Bot stats & live data
- Live bot stats & metrics
- Fully branded & customisable
- Deployed to Vercel in minutes
- HTTPS via ngrok static domain
- Deploys to Vercel in minutes
</td>
</tr>
@@ -95,21 +105,22 @@ ZyroX-CV2-With-Dashboard/
<td>
**🎉 Engagement**
- Leveling system with XP
- Leveling & XP system with leaderboard
- Birthday tracker
- Counting games, blackjack, slots
- AFK system, autorole, autoresponder
- Sticky messages, booster perks
- 12+ mini-games (chess, battleship, wordle, 2048…)
- AFK system, autorole, autoresponder, sticky messages
- Counting, blackjack, slots, booster perks
</td>
<td>
**🔧 Developer**
- Application emoji auto-sync
- Application emoji auto-sync on startup
- Jishaku eval support
- Slash + prefix commands
- FastAPI backend with API key auth
- Hot-patchable emoji.py on startup
- FastAPI backend with API key auth + rate limiting
- ngrok HTTPS tunnel (pyngrok — works on Pterodactyl)
- CodeX Devs watermark on every source file
</td>
</tr>
@@ -117,26 +128,25 @@ ZyroX-CV2-With-Dashboard/
---
## ✦ Quick Start
## ✦ Prerequisites
### Prerequisites
| Requirement | Version |
| Requirement | Version / Notes |
|---|---|
| Python | 3.10 or higher |
| Node.js | 18 or higher |
| A Lavalink node | v4 |
| Lavalink node | v4 |
| Discord bot token | — |
| Discord OAuth app | (for dashboard) |
| Discord OAuth app | for dashboard login |
| ngrok account (free) | for HTTPS tunnel |
---
## ✦ Bot Setup
**1 — Clone and enter the bot folder**
**1 — Clone the repo**
```bash
git clone https://github.com/your-org/ZyroX-CV2-With-Dashboard
git clone https://github.com/RayExo/ZyroX-CV2-With-Dashboard
cd ZyroX-CV2-With-Dashboard/bot
```
@@ -156,34 +166,34 @@ pip install -r requirements.txt
**3 — Configure the environment**
```bash
cp .env.example .env
```
Then edit `.env`:
Copy `.env.example` to `.env` and fill in the values:
```env
# ── Core ──────────────────────────────────────
TOKEN = your_discord_bot_token
brand_name = 'ZyroX'
# ── Core ──────────────────────────────────────────────────────────
TOKEN = your_discord_bot_token
brand_name = 'ZyroX'
# ── Lavalink ──────────────────────────────────
LAVALINK_HOST = "lava-v4.ajieblogs.eu.org"
LAVALINK_PASSWORD = "your_password"
LAVALINK_SECURE = "true" # true = https (no port needed)
LAVALINK_PORT = "" # only needed when LAVALINK_SECURE=false
# ── Lavalink ──────────────────────────────────────────────────────
LAVALINK_HOST = "lava-v4.ajieblogs.eu.org"
LAVALINK_PASSWORD = "your_password"
LAVALINK_SECURE = "true" # true = HTTPS (no port needed)
LAVALINK_PORT = "" # only needed when LAVALINK_SECURE=false
# ── Emoji Sync ────────────────────────────────
EMOJI_SYNC = "true" # auto-uploads & patches emoji.py on startup
# restarts the bot automatically after patching
# ── Emoji Sync ────────────────────────────────────────────────────
EMOJI_SYNC = "true" # auto-uploads & patches emoji.py on startup
# ── API / Dashboard Backend ───────────────────
API_ENABLED = "true" # false = skip starting the FastAPI server
API_PORT = "8000"
DASHBOARD_API_KEY = "change_this_to_a_strong_secret"
# ── API / Dashboard Backend ───────────────────────────────────────
API_ENABLED = "true"
API_PORT = "8000"
DASHBOARD_API_KEY = "change_this_to_a_strong_secret"
# ── Webhooks ──────────────────────────────────
WEBHOOK_URL = "https://discord.com/api/webhooks/..."
# ── HTTPS Tunnel (ngrok) ──────────────────────────────────────────
TUNNEL_ENABLED = "true"
NGROK_AUTHTOKEN = "your_ngrok_authtoken"
NGROK_DOMAIN = "xxxx-xxxx-xxxx.ngrok-free.app"
# ── Webhooks ──────────────────────────────────────────────────────
WEBHOOK_URL = "https://discord.com/api/webhooks/..."
```
**4 — Run the bot**
@@ -205,25 +215,21 @@ npm install
**2 — Configure the environment**
```bash
cp .env.example .env.local
```
Edit `dashboard/.env.local`:
Copy `.env.example` to `.env.local` and fill in the values:
```env
NEXT_PUBLIC_API_URL = http://localhost:8000/api/v1
NEXT_PUBLIC_DASHBOARD_API_KEY = your_shared_api_key # must match bot's DASHBOARD_API_KEY
NEXT_PUBLIC_API_URL = https://xxxx.ngrok-free.app/api/v1
NEXT_PUBLIC_DASHBOARD_API_KEY = your_shared_api_key
NEXTAUTH_URL = http://localhost:3000
NEXTAUTH_SECRET = a_long_random_string
NEXTAUTH_URL = http://localhost:3000
NEXTAUTH_SECRET = a_long_random_string
DISCORD_CLIENT_ID = your_discord_oauth_client_id
DISCORD_CLIENT_SECRET = your_discord_oauth_client_secret
DISCORD_CLIENT_ID = your_discord_oauth_client_id
DISCORD_CLIENT_SECRET = your_discord_oauth_client_secret
NEXT_PUBLIC_ADMIN_IDS = your_discord_user_id
NEXT_PUBLIC_BRAND_NAME = "ZyroX"
NEXT_PUBLIC_BRAND_NAME_WORD = "ZX"
NEXT_PUBLIC_ADMIN_IDS = your_discord_user_id
NEXT_PUBLIC_BRAND_NAME = "ZyroX"
NEXT_PUBLIC_BRAND_NAME_WORD = "ZX"
```
**3 — Run locally**
@@ -252,12 +258,15 @@ Open [http://localhost:3000](http://localhost:3000)
| `API_PORT` | `8000` | Port the backend listens on |
| `DASHBOARD_API_KEY` | — | Shared secret between bot API and dashboard |
| `WEBHOOK_URL` | — | Discord webhook for command logs |
| `TUNNEL_ENABLED` | `true` | Expose the API over HTTPS via ngrok |
| `NGROK_AUTHTOKEN` | — | ngrok auth token |
| `NGROK_DOMAIN` | — | Reserved static domain (e.g. `xxxx.ngrok-free.app`) |
### Dashboard — `dashboard/.env.local`
| Variable | Description |
|---|---|
| `NEXT_PUBLIC_API_URL` | Full URL to the bot's FastAPI backend |
| `NEXT_PUBLIC_API_URL` | Full URL to the bot's FastAPI backend (use ngrok URL in production) |
| `NEXT_PUBLIC_DASHBOARD_API_KEY` | Must match `DASHBOARD_API_KEY` in the bot |
| `NEXTAUTH_URL` | Your dashboard's public URL |
| `NEXTAUTH_SECRET` | Random secret for NextAuth session signing |
@@ -269,94 +278,80 @@ Open [http://localhost:3000](http://localhost:3000)
---
## ✦ HTTPS Tunnel (ngrok)
The bot uses **pyngrok** to expose the API over HTTPS — no system installs needed, works on Pterodactyl and any Python host.
With a free ngrok static domain the URL never changes between restarts.
**One-time setup:**
```bash
# 1. Sign up free at https://ngrok.com
# 2. Get your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken
# 3. Reserve a static domain: https://dashboard.ngrok.com/domains
```
Add to `bot/.env`:
```env
TUNNEL_ENABLED = "true"
NGROK_AUTHTOKEN = "your_token"
NGROK_DOMAIN = "xxxx.ngrok-free.app"
```
On every startup the console prints:
```
◈ Tunnel: API is live at https://xxxx.ngrok-free.app
↳ set NEXT_PUBLIC_API_URL=https://xxxx.ngrok-free.app/api/v1
```
---
## ✦ Deployment
### 🤖 Bot — any Python host
1. Upload the entire `bot/` folder to your host (Render, Railway, Fly.io, VPS…)
1. Upload the entire `bot/` folder to your host (Pterodactyl, Render, Railway, Fly.io, VPS…)
2. Set the start command to `python CodeX.py`
3. Add all environment variables from `.env.example`
4. Make sure port `API_PORT` (`8000` by default) is publicly reachable if you're using the dashboard
3. Add all environment variables
4. pyngrok downloads the ngrok binary automatically on first run — no extra steps
> Recommended free/cheap hosts: [NexioHost](https://nexiohost.in) · Render · Railway
> Recommended free/cheap hosts: Render · Railway · Fly.io · VPS
>
> ⭐ **[NexioHost](https://nexiohost.in)** — Premium bot hosting, built for Discord bots. Fast, reliable, and affordable.
### 🌐 Dashboard — Vercel (recommended)
### 🌐 Dashboard — Vercel
> **That's literally it — upload the folder, add the variables, done.**
**Step 1 — Upload to Vercel**
Go to [vercel.com](https://vercel.com) → **Add New Project** → drag and drop the `dashboard/` folder
*(or connect your GitHub repo and set the root directory to `dashboard/`)*
Vercel auto-detects Next.js — no build settings to touch.
---
**Step 2 — Add environment variables**
In your Vercel project → **Settings → Environment Variables**, add these:
| Variable | Value |
|---|---|
| `NEXT_PUBLIC_API_URL` | Your bot API URL, e.g. `https://your-bot.render.com/api/v1` |
| `NEXT_PUBLIC_DASHBOARD_API_KEY` | Same value as `DASHBOARD_API_KEY` in the bot `.env` |
| `NEXTAUTH_URL` | Your Vercel domain, e.g. `https://your-app.vercel.app` |
| `NEXTAUTH_SECRET` | Any long random string — [generate one here](https://generate-secret.vercel.app/32) |
| `DISCORD_CLIENT_ID` | From [Discord Developer Portal](https://discord.com/developers/applications) |
| `DISCORD_CLIENT_SECRET` | From Discord Developer Portal |
| `NEXT_PUBLIC_ADMIN_IDS` | Your Discord user ID |
| `NEXT_PUBLIC_BRAND_NAME` | `ZyroX` *(or your custom name)* |
| `NEXT_PUBLIC_BRAND_NAME_WORD` | `ZX` *(short version)* |
---
**Step 3 — Add the redirect URI in Discord**
Go to your app in the [Discord Developer Portal](https://discord.com/developers/applications)
**OAuth2 → Redirects** → add:
```
https://your-app.vercel.app/api/auth/callback/discord
```
---
**Step 4 — Deploy**
Hit **Deploy**. Vercel builds and publishes automatically. Your dashboard is live. ✓
1. Go to [vercel.com](https://vercel.com) → **Add New Project** → connect your GitHub repo
2. Set root directory to `dashboard/`
3. Add all environment variables under **Settings → Environment Variables**
4. Add the OAuth redirect URI in Discord Developer Portal:
```
https://your-app.vercel.app/api/auth/callback/discord
```
5. Hit **Deploy** — done ✓
---
## ✦ Emoji Sync
ZyroX includes an automatic emoji sync system that runs on every startup (when `EMOJI_SYNC=true`):
Runs automatically on startup when `EMOJI_SYNC=true`:
```
★ Starting Application Emoji Sync — 140 unique emojis found in emoji.py
◈ Found 140 templates | Application hosts 98 emojis
★ Starting Application Emoji Sync — 144 unique emojis found in emoji.py
◈ Found 144 templates | Application hosts 202 emojis
↑ Uploading: ztick (not in application emojis)
✔ Uploaded: ztick [saved as ID: 1234567890]
✔ emoji.py patched in-place to reflect current API state.
★ Restarting bot to load updated emoji IDs...
```
- **New emoji** → downloaded from CDN, uploaded to your application, ID written to `emoji.py`
- **Stale ID** → `emoji.py` is patched automatically
- **No changes** → sync completes instantly, no restart
- **After any patch** → bot restarts itself so the fresh IDs are live immediately
Set `EMOJI_SYNC=false` to disable entirely.
---
## ✦ Security Notes
- Never commit `.env` files or real tokens to a public repo — `.gitignore` already covers them
- Use a strong, unique `NEXTAUTH_SECRET` and `DASHBOARD_API_KEY`
- Rotate any secret that gets accidentally exposed
- Keep Discord OAuth credentials in environment variables only
- The bot API should always be behind an API key when publicly hosted
| Event | Action |
|---|---|
| New emoji found | Uploaded to application, ID written to `emoji.py` |
| Stale ID detected | `emoji.py` patched automatically |
| No changes | Sync completes instantly, no restart |
| After any patch | Bot restarts itself so fresh IDs are live |
---
@@ -364,52 +359,39 @@ Set `EMOJI_SYNC=false` to disable entirely.
| Problem | Fix |
|---|---|
| Bot fails to start | Check `TOKEN` is set correctly and the bot has the right gateway intents |
| Music not working | Verify `LAVALINK_HOST`, `LAVALINK_SECURE`, and `LAVALINK_PORT` are correct |
| Dashboard shows auth error | Check Discord OAuth client ID/secret and redirect URI in Developer Portal |
| Dashboard can't load data | Confirm `API_ENABLED=true`, the bot is running, and `NEXT_PUBLIC_API_URL` is correct |
| Bot fails to start | Check `TOKEN` is set and bot has correct gateway intents |
| Music not working | Verify `LAVALINK_HOST`, `LAVALINK_SECURE`, and `LAVALINK_PORT` |
| Dashboard auth error | Check Discord OAuth client ID/secret and redirect URI |
| Dashboard can't load data | Confirm `API_ENABLED=true`, bot is running, `NEXT_PUBLIC_API_URL` is correct |
| Emojis showing as plain text | Run with `EMOJI_SYNC=true` once to upload and patch IDs |
| Port conflict on API | Change `API_PORT` in `.env` and update `NEXT_PUBLIC_API_URL` in the dashboard |
| CORS errors from dashboard | Make sure your Vercel URL is in the CORS origins list or add it via `CORS_ORIGINS` env var |
| Tunnel not starting | Check `NGROK_AUTHTOKEN` is valid — get it from [dashboard.ngrok.com](https://dashboard.ngrok.com) |
| Tunnel URL changes on restart | Set `NGROK_DOMAIN` to your reserved static domain |
---
## ✦ Credits & Links
## ✦ Security
- Never commit `.env` files — `.gitignore` already covers them
- Use a strong, unique `NEXTAUTH_SECRET` and `DASHBOARD_API_KEY`
- Rotate any secret that gets accidentally exposed
- The bot API is always behind an API key — never expose it without one
---
<div align="center">
Developed with ❤️ by **CodeX Devs**
## ✦ CodeX Devs
[![Discord](https://img.shields.io/badge/Join_Support_Server-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/codexdev)
[![Hosting](https://img.shields.io/badge/Bot_Hosting-NexioHost-FF6B6B?style=for-the-badge)](https://nexiohost.in)
</div>
---
## ✦ License
```
MIT License — Copyright (c) 2026 CodeX Devs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
```
<div align="center">
---
*ZyroX — Built for protection. Designed for style.*
*Built for protection. Designed for style.*
<p>
<a href="https://discord.gg/codexdev"><img src="https://img.shields.io/badge/Discord-Join_Server-5865F2?style=for-the-badge&logo=discord&logoColor=white"/></a>
<a href="https://youtube.com/@CodeXDevs"><img src="https://img.shields.io/badge/YouTube-CodeXDevs-FF0000?style=for-the-badge&logo=youtube&logoColor=white"/></a>
<a href="https://github.com/RayExo"><img src="https://img.shields.io/badge/GitHub-RayExo-181717?style=for-the-badge&logo=github&logoColor=white"/></a>
<a href="https://nexiohost.in"><img src="https://img.shields.io/badge/⭐%20PREMIUM%20HOSTING-NexioHost-FFD700?style=for-the-badge&labelColor=1a1a2e&color=FFD700&logoColor=FFD700"/></a>
</p>
© 2026 CodeX Devs — MIT License
</div>