📄
pasted-code-1787750945351.txt
txt
999 lines
▶
Create a production-ready Discord whitelist application bot for my Minecraft server **SpikeSMP**.
IMPORTANT:
* I already have the Minecraft/Paper plugin.
* DO NOT create, modify, or replace the Minecraft plugin.
* DO NOT create a Minecraft plugin.
* Build ONLY the Discord bot.
* The bot must communicate with my existing Minecraft plugin through its HTTP API.
* The bot must NOT execute Minecraft console commands directly.
* Do not use RCON.
* Do not use SSH.
* Do not use `/lp` directly from Discord.
* The existing plugin/API is responsible for Minecraft whitelist and LuckPerms actions.
## 1. Technology
Use:
* Python 3.11+
* discord.py 2.x
* aiohttp
* python-dotenv
* SQLite for persistent application/ticket data
* Async code throughout
* Environment variables for all secrets/configuration
The project must be ready to run on a Pterodactyl Python egg.
## 2. Required project structure
Create:
```text
SpikeSMP-Whitelist-Bot/
│
├── main.py
├── bot.py
├── config.py
├── database.py
├── api_client.py
├── whitelist.py
├── tickets.py
├── views.py
├── questions.py
├── requirements.txt
├── .env.example
├── .gitignore
└── README.md
```
Do not leave important functionality as pseudocode.
All files must contain complete working code.
## 3. Environment variables
Use exactly these variables:
```env
DISCORD_TOKEN=PUT_BOT_TOKEN_HERE
GUILD_ID=PUT_DISCORD_SERVER_ID_HERE
WHITELIST_ROLE_ID=PUT_ROLE_ID_HERE
OWNER_ROLE_ID=PUT_OWNER_ROLE_ID_HERE
TICKET_CATEGORY_ID=PUT_CATEGORY_ID_HERE
PLUGIN_API_URL=http://127.0.0.1:8081
PLUGIN_API_SECRET=CHANGE_THIS_SECRET
BOT_PORT=3000
```
Do not hardcode tokens, IDs, passwords, or secrets.
Add validation on startup so the bot clearly reports which environment variable is missing.
## 4. Main whitelist system
Create a Discord command:
```text
/whitelist
```
Also provide a persistent button named:
```text
@Whitelist
```
The button should be usable from a permanent whitelist panel.
When a player clicks the button:
1. Check whether they already have an active whitelist ticket.
2. If yes:
* Tell them they already have an application open.
* Provide the existing ticket channel.
3. If no:
* Create a private ticket channel.
* Put it inside `TICKET_CATEGORY_ID`.
* Allow access to:
* applicant
* bot
* members with `OWNER_ROLE_ID`
* Deny access to everyone else.
Use a clean ticket name such as:
```text
whitelist-username
```
## 5. Ticket opening message
When the ticket is created, send an attractive embed:
Title:
```text
SpikeSMP Whitelist Application
```
Description:
```text
Welcome to the SpikeSMP whitelist application.
Answer every question honestly.
Minimum requirements:
• Age: 12+
• Daily availability: 4+ hours
• Maximum other SMPs: 1
Your application will be reviewed automatically first.
If it does not meet the automatic requirements, it will be sent to the Owner for manual review.
```
Add a button:
```text
Start Application
```
Do NOT immediately ask questions until the player presses Start Application.
## 6. Application questions
Ask questions one at a time.
Store every answer in SQLite.
### Question 1
```text
What type of player are you?
```
Buttons:
```text
PvPer
Grinder
Both
```
Accept only these choices.
### Question 2
```text
How old are you?
```
Use a Discord modal/text input.
Validate that the answer is a whole number.
Minimum:
```text
12
```
If below 12, mark the application as failed.
Do not insult or shame the applicant.
### Question 3
```text
How much time can you give SpikeSMP daily?
```
Ask for hours.
Minimum:
```text
4 hours
```
Accept values such as:
```text
4
5
6
4.5
```
Reject invalid values.
If below 4 hours, mark the application as failed.
### Question 4
```text
What is your timezone/country?
```
Examples:
```text
India
Bangladesh
Pakistan
Nepal
UTC+5:30
```
Store the answer as text.
### Question 5
```text
Have you ever played SpikeSMP before?
```
Buttons:
```text
Yes
No
```
## 7. Existing SpikeSMP player flow
If they select:
```text
Yes
```
ask:
```text
How many SpikeSMP seasons have you played?
```
Accept a number.
Then ask:
```text
Which season(s) have you won?
Examples:
S1
S4
S9
S1, S4
S2, S6, S9
If you have not won any season, type:
None
```
Parse season names safely.
Valid seasons:
```text
S1
S2
S3
S4
S5
S6
S7
S8
S9
```
Normalize inputs such as:
```text
s1
S1
season 1
Season 1
```
into:
```text
S1
```
If the player says:
```text
None
```
they receive no season winner rank.
If they list:
```text
S1
S4
S9
```
store:
```json
["S1", "S4", "S9"]
```
The bot should send these season ranks to the existing plugin API.
IMPORTANT:
The bot itself must NOT run LuckPerms commands.
The existing Minecraft plugin will handle the actual rank assignment.
## 8. New player flow
If they select:
```text
No
```
ask:
```text
How many other SMPs are you currently playing on?
```
Accept a whole number.
Allowed automatic values:
```text
0
1
```
If:
```text
2+
```
the application must NOT be automatically approved.
It must go to Owner/manual review.
## 9. Automatic eligibility
After all questions are answered, calculate:
```text
age >= 12
daily_hours >= 4
other_smp_count <= 1
```
For previous SpikeSMP players, the other-SMP question is NOT required.
For new players, `other_smp_count` must be `0` or `1` for automatic approval.
The player type and timezone are collected as application information and shown to the Owner.
## 10. Automatic approval
If the application passes the automatic requirements:
Send an embed:
```text
Whitelist Application Approved
```
Show:
```text
Applicant
IGN
Player Type
Age
Daily Hours
Timezone
Previous SpikeSMP Player
Seasons Played
Seasons Won
```
Then call the existing Minecraft plugin API.
The API request should contain:
```json
{
"ign": "PLAYER_IGN",
"discord_id": "DISCORD_USER_ID",
"player_type": "Both",
"age": 16,
"daily_hours": 5,
"timezone": "India",
"played_before": true,
"seasons_played": 4,
"seasons_won": ["S1", "S4"]
}
```
The bot must wait for the plugin API response.
Only tell the player they are whitelisted if the API confirms success.
## 11. IGN collection
The bot MUST collect the applicant's Minecraft IGN.
Ask:
```text
What is your Minecraft username/IGN?
```
Validate it reasonably for Minecraft usernames.
Do not blindly trust malformed input.
Store it in the application database.
## 12. Plugin API
Create a dedicated:
```text
api_client.py
```
Use:
```env
PLUGIN_API_URL
PLUGIN_API_SECRET
```
Every request to the plugin must include the secret securely, for example through an authorization header.
Never expose:
```text
PLUGIN_API_SECRET
```
in Discord messages.
Create a clean API abstraction such as:
```python
async def whitelist_player(...)
async def assign_season_rank(...)
async def process_application(...)
```
The exact API endpoint paths should be configurable or clearly centralized in `api_client.py`.
If the existing plugin API uses different endpoint names, make them easy to change in one place.
## 13. Suggested API contract
Design the bot around these logical API operations:
```text
POST /api/whitelist
POST /api/rank
POST /api/application
```
Example whitelist request:
```json
{
"ign": "PlayerName",
"discord_id": "123456789"
}
```
Example rank request:
```json
{
"ign": "PlayerName",
"rank": "S6"
}
```
The API should return JSON similar to:
```json
{
"success": true,
"message": "Player whitelisted"
}
```
or:
```json
{
"success": false,
"message": "Player not found"
}
```
Handle API failures gracefully.
Never claim that a player has been whitelisted when the API returned failure or timed out.
## 14. LuckPerms rank logic
If the player won seasons:
```text
S1 -> S1
S2 -> S2
S3 -> S3
S4 -> S4
S5 -> S5
S6 -> S6
S7 -> S7
S8 -> S8
S9 -> S9
```
The bot sends the appropriate rank identifier to the Minecraft plugin.
The plugin performs the actual LuckPerms command/action.
If the player won multiple seasons, send all valid seasons.
Do not invent ranks that were not supplied by the applicant.
## 15. Manual review
If an application fails automatic requirements OR contains a condition requiring manual review:
Do NOT whitelist the player.
Send an Owner-only review message in the ticket.
Include:
```text
SpikeSMP Whitelist — Manual Review
IGN:
Discord:
Player Type:
Age:
Daily Hours:
Timezone:
Played SpikeSMP:
Seasons Played:
Seasons Won:
Other SMPs:
Automatic Result:
MANUAL REVIEW REQUIRED
Reason:
```
Buttons:
```text
Approve
Deny
```
Only users with `OWNER_ROLE_ID` can use these buttons.
Staff without the Owner role must not be able to approve.
## 16. Owner approval
When an Owner presses:
```text
Approve
```
the bot must:
1. Verify the user still has `OWNER_ROLE_ID`.
2. Call the plugin API.
3. Wait for successful API response.
4. Add `WHITELIST_ROLE_ID` to the Discord applicant.
5. If season wins exist, request corresponding ranks through the plugin API.
6. Send a success embed.
7. Log the decision.
8. Optionally disable/lock the ticket.
9. Never report success if the API failed.
Approval message:
```text
Whitelist Approved
Your SpikeSMP whitelist application has been approved by the Owner.
Your Minecraft account has been processed successfully.
```
## 17. Owner denial
When Owner presses:
```text
Deny
```
show a modal asking:
```text
Reason for denial
```
Store the reason.
Send:
```text
Whitelist Application Denied
Your application was not approved.
Reason:
```
Do NOT call the whitelist API.
Do NOT give the Discord whitelist role.
Do NOT assign any Minecraft rank.
## 18. Discord role
`WHITELIST_ROLE_ID` is the Discord role that should be added after successful approval.
Never give this role before Minecraft whitelist succeeds.
If Discord role assignment fails, report that separately and log it.
## 19. Ticket controls
Add a button:
```text
Close Ticket
```
Only the applicant, Owner, or bot should be able to close it.
Before closing, save all application information.
When closed:
* Rename channel to `closed-whitelist-username`
* Remove applicant's send permission
* Keep Owner access
* Send final transcript/summary
* Mark application closed in SQLite
## 20. Persistent buttons
The bot must use persistent Discord views so buttons continue working after:
```text
bot restart
server restart
Pterodactyl restart
```
Use stable `custom_id` values.
Register persistent views on startup.
## 21. SQLite database
Create tables for:
### applications
```text
id
discord_id
minecraft_ign
ticket_channel_id
player_type
age
daily_hours
timezone
played_before
seasons_played
seasons_won
other_smp_count
status
failure_reason
owner_id
owner_reason
created_at
updated_at
```
### tickets
```text
channel_id
discord_id
application_id
status
created_at
closed_at
```
Prevent duplicate active applications.
## 22. Logging
Create clean console logs:
```text
[INFO] Bot starting
[INFO] Connected to Discord
[INFO] Database initialized
[INFO] Whitelist panel loaded
[INFO] Application started: DiscordID
[INFO] API whitelist request: IGN
[INFO] API response: SUCCESS
[INFO] Owner approved application: IGN
[ERROR] Plugin API unavailable
```
Do not log:
* Discord token
* API secret
* passwords
## 23. Error handling
Handle:
* Discord API errors
* Missing permissions
* Missing category
* Missing roles
* API timeout
* API unavailable
* Invalid API response
* Duplicate applications
* Bot restart
* Database errors
* Invalid user input
* User leaving the Discord server
* Ticket deleted manually
The bot should not crash because of one bad application.
## 24. Rate limiting
Prevent spam.
A user should not be able to create unlimited whitelist tickets.
Add a configurable cooldown/rate limit.
If they already have an active ticket, never create another.
## 25. Security
IMPORTANT SECURITY REQUIREMENTS:
* Never expose plugin API secret.
* Never put secrets in Discord embeds.
* Never trust Discord user input.
* Never allow normal members to use Owner approval buttons.
* Verify Owner role every time an approval/denial button is pressed.
* Validate IGN.
* Validate numeric answers.
* Sanitize channel names.
* Use HTTPS when deployed remotely.
* Add reasonable API timeouts.
* Do not execute arbitrary commands received from Discord.
* Do not accept arbitrary LuckPerms command strings.
* Only allow season ranks S1-S9.
## 26. UI design
Make the Discord interface professional.
Use embeds.
Use buttons.
Use clear status indicators:
```text
Application Started
Under Review
Approved
Denied
```
Use consistent SpikeSMP branding.
Avoid excessive emojis.
Example application summary:
```text
⚡ SpikeSMP Whitelist
Applicant
Minecraft: PlayerName
Discord: @Player
Profile
Type: Both
Age: 16
Daily Time: 5 hours
Timezone: India
History
Played SpikeSMP: Yes
Seasons Played: 4
Seasons Won: S1, S4
Status
APPROVED
```
## 27. Slash commands
Implement:
```text
/whitelist
```
Creates or displays the whitelist application panel.
Owner-only:
```text
/whitelist-review
```
Shows pending manual applications.
Owner-only:
```text
/whitelist-status
```
Checks the bot/plugin API status for a player if supported by the API.
Owner-only:
```text
/whitelist-close
```
Closes the current whitelist ticket.
## 28. Startup behavior
On startup:
1. Load `.env`.
2. Validate configuration.
3. Initialize SQLite.
4. Connect to Discord.
5. Sync slash commands to `GUILD_ID`.
6. Register persistent views.
7. Verify plugin API availability.
8. Log startup status.
If the plugin API is offline, the bot should still start, but whitelist approvals should show:
```text
Minecraft service currently unavailable.
Please try again later.
```
Do not falsely approve anyone.
## 29. README
Create a complete README containing:
* Installation
* Python version
* Pterodactyl deployment
* Environment variables
* Discord bot permissions
* Required Discord intents
* Creating the ticket category
* Getting Discord IDs
* Setting up the whitelist panel
* Plugin API configuration
* Starting the bot
* Troubleshooting
* API contract
* Security notes
Include the Pterodactyl startup command:
```text
python main.py
```
## 30. requirements.txt
Include all required packages with compatible versions, for example:
```text
discord.py
aiohttp
python-dotenv
```
Do not add unnecessary packages.
## 31. .env.example
Create:
```env
DISCORD_TOKEN=PUT_BOT_TOKEN_HERE
GUILD_ID=PUT_DISCORD_SERVER_ID_HERE
WHITELIST_ROLE_ID=PUT_ROLE_ID_HERE
OWNER_ROLE_ID=PUT_OWNER_ROLE_ID_HERE
TICKET_CATEGORY_ID=PUT_CATEGORY_ID_HERE
PLUGIN_API_URL=http://127.0.0.1:8081
PLUGIN_API_SECRET=CHANGE_THIS_SECRET
BOT_PORT=3000
```
## 32. Final requirement
After generating the project:
1. Show the complete file tree.
2. Provide the complete contents of every required file.
3. Make sure imports match the file structure.
4. Make sure there are no undefined functions.
5. Make sure persistent buttons work after restart.
6. Make sure SQLite initialization happens automatically.
7. Make sure the bot can run with:
```bash
python main.py
```
8. Make sure there are no fake API responses.
9. Clearly identify where the existing Minecraft plugin API endpoints should be adjusted if its API uses different paths.
10. Do not generate a Minecraft plugin.
The final result must be a complete, runnable **SpikeSMP Discord Whitelist Bot** that uses my existing Minecraft plugin as the Minecraft-side whitelist/LuckPerms controller.
Create the configuration, persistence, API, validation, and ticket layers.
Create the Discord views and whitelist application workflow with persistent custom IDs.
Create the bot entry point, dependency metadata, environment template, ignore rules, and deployment README.
Created the complete SpikeSMP Discord whitelist bot.
SpikeSMP-Whitelist-Bot/
├── main.py
├── bot.py
├── config.py
├── database.py
├── api_client.py
├── whitelist.py
├── tickets.py
├── views.py
├── questions.py
├── requirements.txt
├── .env.example
├── .gitignore
└── README.md
Included:
Persistent
@Whitelist, application, review, and ticket buttons/whitelist/whitelist-review/whitelist-status <ign>/whitelist-closeSQLite application and ticket persistence
Automatic eligibility checks
Owner-only manual approval and denial
Minecraft IGN validation
Season parsing restricted to
S1–S9Plugin API abstraction using
aiohttpSecure API secret authorization headers
Discord whitelist role assignment only after API success
Ticket permission isolation and closing summaries
Duplicate application prevention and cooldown protection
Startup environment validation
Pterodactyl deployment instructions
No Minecraft plugin, RCON, SSH, console commands, or direct LuckPerms commands
If the existing plugin uses different API paths, adjust the centralized constants in api_client.py:
PluginApiClient.APPLICATION_ENDPOINT
PluginApiClient.WHITELIST_ENDPOINT
PluginApiClient.RANK_ENDPOINT
Run it with:
python main.py
from __future__ import annotations
import logging
from bot import SpikeSMPBot
from config import ConfigError, Settings
def configure_logging() -> None:
logging.basicConfig(level=logging.INFO, format="[%(levelname)s] %(message)s")
def main() -> None:
configure_logging()
try:
settings = Settings.from_environment()
except ConfigError as exc:
logging.getLogger(__name__).error("Configuration error: %s", exc)
return
bot = SpikeSMPBot(settings)
bot.run(settings.discord_token, log_handler=None)
if __name__ == "__main__":
main()