Skill: thebigbrainchad/discordadmin (version 1.0.0)

--- name: discord-server-ctrl description: Complete A-Z Discord server administration. Channel/role/member management, AutoMod, webhooks, templates, audit logs, scheduled events, threads, and full server control via CLI. --- # Discord Server Admin (Pro) A complete, enterprise-grade Discord server management skill. Everything a real server admin needs — from basic moderation to AutoMod, webhooks, templates, audit logs, and beyond. --- ## 🚀 Quick Start ```bash # Set your bot token export DISCORD_BOT_TOKEN="your-bot-token" # Make script executable chmod +x discord-admin.sh # View all commands ./discord-admin.sh --help ``` --- ## 📋 Command Reference ### 1. Server Intelligence ```bash # Full server overview ./discord-admin.sh server-info <guildId> # Server vanity URL (if enabled) ./discord-admin.sh vanity-get <guildId> # Set vanity URL (requires DISCOVERABLE + boosts) ./discord-admin.sh vanity-set <guildId> <code> # Server template operations ./discord-admin.sh template-list <guildId> # List templates ./discord-admin.sh template-create <guildId> <name> # Create template ./discord-admin.sh template-use <code> # Create server from template ``` ### 2. Channel Management (All Types) ```bash # List ALL channels (organized by category) ./discord-admin.sh channel-list <guildId> # Create channels ./discord-admin.sh channel-create <guildId> <name> text # Text ./discord-admin.sh channel-create <guildId> <name> voice # Voice ./discord-admin.sh channel-create <guildId> <name> category # Category ./discord-admin.sh channel-create <guildId> <name> forum # Forum ./discord-admin.sh channel-create <guildId> <name> stage # Stage ./discord-admin.sh channel-create <guildId> <name> announcements # Announcement # Edit channel (all settings) ./discord-admin.sh channel-edit <guildId> <channelId> name:<newName> topic:<topic> ./discord-admin.sh channel-edit <guildId> <channelId> nsfw:true rateLimit:60 # Channel permissions ./discord-admin.sh channel-perms <guildId> <channelId> # View perms ./discord-admin.sh channel-perms-set <guildId> <channelId> <roleId> allow:<perms> deny:<perms> ./discord-admin.sh channel-perms-overwrite <guildId> <channelId> <targetId> <type:role|user> allow:<perms> deny:<perms> # Delete channel ./discord-admin.sh channel-delete <guildId> <channelId> # Bulk operations ./discord-admin.sh channel-prune <guildId> <days:7> # Delete unused channels ``` ### 3. Role Management (Advanced) ```bash # List all roles with hierarchy ./discord-admin.sh role-list <guildId> # Create role with full permissions ./discord-admin.sh role-create <guildId> <name> color:#FF5500 permissions:ADMINISTRATOR ./discord-admin.sh role-create <guildId> <name> permissions:MANAGE_CHANNELS,KICK_MEMBERS,BAN_MEMBERS # Edit role ./discord-admin.sh role-edit <guildId> <roleId> name:<name> color:<hex> ./discord-admin.sh role-edit <guildId> <roleId> hoist:true mentionable:true ./discord-admin.sh role-edit <guildId> <roleId> permissions:+MANAGE_MESSAGES,-ADMINISTRATOR # Position management (hierarchy matters!) ./discord-admin.sh role-position <guildId> <roleId> <newPosition> # Delete role ./discord-admin.sh role-delete <guildId> <roleId> # Bulk role operations ./discord-admin.sh role-assign-bulk <guildId> <roleId> <userId1,userId2,...> ./discord-admin.sh role-remove-bulk <guildId> <roleId> <userId1,userId2,...> # Role permission constants (comma-separated): # ADMINISTRATOR, VIEW_AUDIT_LOG, VIEW_GUILD_INSIGHTS, MANAGE_GUILD, MANAGE_ROLES, MANAGE_CHANNELS, KICK_MEMBERS, BAN_MEMBERS, CREATE_INSTANT_INVITE, CHANGE_NICKNAME, MANAGE_NICKNAMES, MANAGE_EMOJIS, MANAGE_WEBHOOKS, MANAGE_GUILD_EXPRESSIONS, USE_APPLICATION_COMMANDS, MANAGE_EVENTS, MODERATE_MEMBERS ``` ### 4. Member Management ```bash # Member info ./discord-admin.sh member-info <guildId> <userId> # Nickname management ./discord-admin.sh member-nick <guildId> <userId> <nickname> ./discord-admin.sh member-nick-reset <guildId> <userId> # Timeout (mute) - Discord native ./discord-admin.sh member-timeout <guildId> <userId> <duration:60s|1h|1d|7d> ./discord-admin.sh member-untimeout <guildId> <userId> # Kick ./discord-admin.sh member-kick <guildId> <userId> [reason] # Ban (with options) ./discord-admin.sh member-ban <guildId> <userId> [reason] [deleteMessageDays:0-7] ./discord-admin.sh member-ban-temp <guildId> <userId> <duration:7d> [reason] # Unban ./discord-admin.sh member-unban <guildId> <userId> [reason] # Bulk moderation ./discord-admin.sh ban-list <guildId> # List all bans ./discord-admin.sh kick-bulk <guildId> <userId1,userId2,...> [reason] ./discord-admin.sh ban-bulk <guildId> <userId1,userId2,...> [reason] # Avatar management ./discord-admin.sh member-avatar-set <guildId> <userId> <imageUrl> ``` ### 5. AutoMod (Pro Feature) ```bash # List AutoMod rules ./discord-admin.sh automod-list <guildId> # Create AutoMod rule ./discord-admin.sh automod-create <guildId> <name> \ keyword:badword,spam,scam \ presets:SLUR,SEXUAL,PROFANITY \ actions:BLOCK_MESSAGE,ALERT, timeout:60s # Keyword filters ./discord-admin.sh automod-keyword <guildId> <ruleName> add:badword,offensive ./discord-admin.sh automod-keyword <guildId> <ruleName> remove:badword ./discord-admin.sh automod-keyword <guildId> <ruleName> clear:true # Preset filters (Discord-provided) ./discord-admin.sh automod-preset <guildId> <ruleName> SLUR,SEXUAL,PROFANITY,VIOLENCE # Regex patterns ./discord-admin.sh automod-regex <guildId> <ruleName> pattern:'(?i)(https?://\S+)' # Block lists ./discord-admin.sh automod-blocklist <guildId> <ruleName> add:custom_blocklist_name # Actions configuration ./discord-admin.sh automod-actions <guildId> <ruleName> \ ALERT \ BLOCK_MESSAGE \ timeout:60s \ timeoutDuration:300 \ channelId:123456789 # Edit/delete rules ./discord-admin.sh automod-edit <guildId> <ruleId> enabled:false ./discord-admin.sh automod-delete <guildId> <ruleId> ``` ### 6. Message Management ```bash # Send messages ./discord-admin.sh msg-send <channelId> <content> ./discord-admin.sh msg-embed <channelId> '{"title":"Hello","description":"World","color":65280}' # Send with attachments ./discord-admin.sh msg-send-file <channelId> <filePath> [message] # Edit messages ./discord-admin.sh msg-edit <channelId> <messageId> <newContent> # Delete messages ./discord-admin.sh msg-delete <channelId> <messageId> ./discord-admin.sh msg-delete-bulk <channelId> <messageId1,messageId2,...> ./discord-admin.sh msg-delete-range <channelId> <beforeMessageId> [limit:100] # Bulk delete (14-day limit) ./discord-admin.sh msg-prune <channelId> [days:7] # Search messages ./discord-admin.sh msg-search <guildId> <query> [channelId] ./discord-admin.sh msg-search-user <guildId> <userId> [limit:100] # Pin/Unpin ./discord-admin.sh msg-pin <channelId> <messageId> ./discord-admin.sh msg-unpin <channelId> <messageId> ./discord-admin.sh msg-pins <channelId> # Get message history ./discord-admin.sh msg-history <channelId> [limit:100] ``` ### 7. Webhooks (Advanced) ```bash # List webhooks ./discord-admin.sh webhook-list <guildId> [channelId] ./discord-admin.sh webhook-list <guildId> <channelId> # Create webhook ./discord-admin.sh webhook-create <channelId> <name> [avatarUrl] # Get webhook info ./discord-admin.sh webhook-info <webhookId> # Edit webhook ./discord-admin.sh webhook-edit <webhookId> name:<name> channel:<channelId> ./discord-admin.sh webhook-edit <webhookId> avatar:<imageUrl> # Execute webhook (send as webhook) ./discord-admin.sh webhook-execute <webhookId> <content> ./discord-admin.sh webhook-execute <webhookId> <content> username:<customName> avatar:<customAvatar> ./discord-admin.sh webhook-execute <webhookId> <content> tts:true ./discord-admin.sh webhook-execute <webhookId> embed:'{"title":"Embed","description":"内容"}' # Delete webhook ./discord-admin.sh webhook-delete <webhookId> ``` ### 8. Emojis & Stickers ```bash # List emojis ./discord-admin.sh emoji-list <guildId> # Create emoji (from URL or base64) ./discord-admin.sh emoji-create <guildId> <name> <imageUrl> ./discord-admin.sh emoji-create <guildId> <name> <base64Data> # Delete emoji ./discord-admin.sh emoji-delete <guildId> <emojiId> # Modify emoji ./discord-admin.sh emoji-edit <guildId> <emojiId> <newName> # List stickers ./discord-admin.sh sticker-list <guildId> # Create sticker ./discord-admin.sh sticker-create <guildId> <name> <tag> <imageUrl> # Edit sticker ./discord-admin.sh sticker-edit <guildId> <stickerId> name:<name> tags:<tags> # Delete sticker ./discord-admin.sh sticker-delete <guildId> <stickerId> ``` ### 9. Soundboard (Beta) ```bash # List soundboard sounds ./discord-admin.sh soundboard-list <guildId> # Play sound (triggers in voice channel) ./discord-admin.sh soundboard-play <guildId> <soundId> [volume:100] # Default sounds ./discord-admin.sh soundboard-defaults <guildId> ``` ### 10. Scheduled Events ```bash # List events ./discord-admin.sh event-list <guildId> # Create event ./discord-admin.sh event-create <guildId> <name> <description> <startTime> endTime:<endTime> channel:<channelId> ./discord-admin.sh event-create <guildId> "Gaming Night" "Join us!" 2024-12-31T20:00:00Z channel:123456789 entityType:VOICE # Event types: VOICE, STAGE_INSTANCE, EXTERNAL # Edit event ./discord-admin.sh event-edit <guildId> <eventId> name:<name> description:<desc> ./discord-admin.sh event-edit <guildId> <eventId> status:SCHEDULED|ACTIVE|COMPLETED|CANCELED # Delete event ./discord-admin.sh event-delete <guildId> <eventId> ``` ### 11. Invites ```bash # List invites ./discord-admin.sh invite-list <guildId> # Create invite ./discord-admin.sh invite-create <channelId> [maxUses:0] [maxAge:86400] [temporary:true] ./discord-admin.sh invite-create <channelId> maxUses:100 maxAge:3600 unique:true # Get invite info ./discord-admin.sh invite-info <inviteCode> # Delete invite ./discord-admin.sh invite-delete <guildId> <inviteCode> # Vanity URL (server setting) ./discord-admin.sh vanity-get <guildId> ./discord-admin.sh vanity-set <guildId> <code> ``` ### 12. Audit Logs ```bash # Get audit logs ./discord-admin.sh audit-logs <guildId> [limit:100] ./discord-admin.sh audit-logs <guildId> user:<userId> ./discord-admin.sh audit-logs <guildId> action:CHANNEL_CREATE,BAN,KICK # Audit action types: # GUILD_UPDATE, CHANNEL_CREATE, CHANNEL_UPDATE, CHANNEL_DELETE, CHANNEL_OVERWRITE_CREATE, CHANNEL_OVERWRITE_UPDATE, CHANNEL_OVERWRITE_DELETE, MEMBER_KICK, MEMBER_PRUNE, BAN_ADD, BAN_REMOVE, MEMBER_UPDATE, MEMBER_ROLE_UPDATE, ROLE_CREATE, ROLE_UPDATE, ROLE_DELETE, INVITE_CREATE, INVITE_UPDATE, INVITE_DELETE, WEBHOOK_CREATE, WEBHOOK_UPDATE, WEBHOOK_DELETE, EMOJI_CREATE, EMOJI_UPDATE, EMOJI_DELETE, MESSAGE_DELETE, MESSAGE_BULK_DELETE, MESSAGE_PIN, MESSAGE_UNPIN, STAGE_INSTANCE_CREATE, STAGE_INSTANCE_UPDATE, STAGE_INSTANCE_DELETE, THREAD_CREATE, THREAD_UPDATE, THREAD_DELETE ``` ### 13. Thread Management ```bash # List threads ./discord-admin.sh thread-list <guildId> ./discord-admin.sh thread-list <channelId> # Create thread ./discord-admin.sh thread-create <channelId> <name> <messageId> [autoArchive:1440] ./discord-admin.sh thread-create <channelId> <name> autoArchive:4320 # Edit thread ./discord-admin.sh thread-edit <threadId> name:<name> archived:true ./discord-admin.sh thread-edit <threadId> locked:true autoArchive:10080 # Delete thread ./discord-admin.sh thread-delete <threadId> # Join/Leave thread ./discord-admin.sh thread-join <threadId> ./discord-admin.sh thread-leave <threadId> ``` ### 14. Stage Channels ```bash # Create stage instance ./discord-admin.sh stage-create <channelId> [topic:"Open Mic"] # Edit stage ./discord-admin.sh stage-edit <channelId> topic:<topic> privacyLevel:GUILD_ONLY ./discord-admin.sh stage-edit <channelId> scheduledStart:<ISO8601> # Close stage ./discord-admin.sh stage-close <channelId> ``` ### 15. Integration Management ```bash # List integrations (bots, apps) ./discord-admin.sh integration-list <guildId> # Integration operations ./discord-admin.sh integration-sync <guildId> <integrationId> ./discord-admin.sh integration-delete <guildId> <integrationId> ``` ### 16. Guild Settings ```bash # Edit server settings ./discord-admin.sh guild-edit <guildId> name:<newName> ./discord-admin.sh guild-edit <guildId> icon:<imageUrl> ./discord-admin.sh guild-edit <guildId> splash:<imageUrl> ./discord-admin.sh guild-edit <guildId> region:<voiceRegion> ./discord-admin.sh guild-edit <guildId> afkChannel:<channelId> afkTimeout:900 ./discord-admin.sh guild-edit <guildId> systemChannel:<channelId> notifications:ALL_MESSAGES ./discord-admin.sh guild-edit <guildId> explicitContentFilter:ALL_MEMBERS ./discord-admin.sh guild-edit <guildId> mfaLevel:ELEVATED ./discord-admin.sh guild-edit <guildId> verificationLevel:HIGH ./discord-admin.sh guild-edit <guildId> defaultNotifications:ALL_MESSAGES # Community features ./discord-admin.sh guild-enable-community <guildId> ./discord-admin.sh guild-disable-community <guildId> # Server merge/transfer ./discord-admin.sh guild-transfer <guildId> <newOwnerId> ``` ### 17. Widget Management ```bash # Widget settings ./discord-admin.sh widget-get <guildId> ./discord-admin.sh widget-edit <guildId> enabled:true channel:<channelId> ``` ### 18. Moderation Logging ```bash # Setup moderation log ./discord-admin.sh modlog-set <guildId> <channelId> ./discord-admin.sh modlog-get <guildId> ./discord-admin.sh modlog-disable <guildId> # Configuration ./discord-admin.sh modlog-config <guildId> \ kicks:true \ bans:true \ messages:true \ nickname:true \ roles:true \ invites:true ``` ### 19. Bulk/Mass Operations ```bash # Mass ban ./discord-admin.sh mass-ban <guildId> <userIdsFileOrComma> [reason] # Mass kick ./discord-admin.sh mass-kick <guildId> <userIdsFileOrComma> [reason] # Mass role assignment ./discord-admin.sh mass-role <guildId> <roleId> <userIdsFileOrComma> # Channel sync (copy permissions) ./discord-admin.sh channel-sync-perms <sourceChannelId> <targetChannelId> # Role sync (copy all settings) ./discord-admin.sh role-clone <guildId> <roleId> <newName> ``` ### 20. Template Operations ```bash # Templates ./discord-admin.sh template-list <guildId> ./discord-admin.sh template-create <guildId> <name> [description] ./discord-admin.sh template-sync <guildId> <templateCode> ./discord-admin.sh template-delete <guildId> <templateId> # Create server from template ./discord-admin.sh template-use <templateCode> <newServerName> ``` --- ## ⚙️ Configuration ### Environment Variables ```bash export DISCORD_BOT_TOKEN="your-bot-token" export DISCORD_GUILD_ID="default-guild-id" export DISCORD_DEFAULT_TIMEOUT=60 # API timeout in seconds export DISCORD_MAX_RETRIES=3 # Retry on rate limit export DISCORD_OUTPUT_FORMAT="json" # json, pretty, minimal ``` ### Required Permissions **Option A: Administrator (easiest)** - Requires: `ADMINISTRATOR` permission **Option B: Granular permissions** ``` MANAGE_CHANNELS MANAGE_ROLES KICK_MEMBERS BAN_MEMBERS MANAGE_MESSAGES MANAGE_GUILD VIEW_AUDIT_LOG MANAGE_EMOJIS MANAGE_WEBHOOKS MANAGE_GUILD_EXPRESSIONS MANAGE_EVENTS MODERATE_MEMBERS ``` ### Rate Limiting The script handles Discord's rate limits automatically: - 1 req/1s per channel for message sends - 50 req/10s for other operations - Exponential backoff on 429 errors - Global rate limit detection --- ## 📊 Examples ### Complete Server Setup ```bash #!/bin/bash # Setup a new community server from scratch GUILD="123456789" [REDACTED_SECRET]" # 1. Create roles ./discord-admin.sh role-create $GUILD "Admin" color:#FF0000 permissions:ADMINISTRATOR ./discord-admin.sh role-create $GUILD "Moderator" color:#FFA500 permissions:KICK_MEMBERS,BAN_MEMBERS,MANAGE_MESSAGES ./discord-admin.sh role-create $GUILD "Member" color:#00FF00 permissions:CREATE_INSTANT_INVITE # 2. Create channels ./discord-admin.sh channel-create $GUILD "general" text ./discord-admin.sh channel-create $GUILD "announcements" announcements ./discord-admin.sh channel-create $GUILD "Voice Channels" category # 3. Setup AutoMod ./discord-admin.sh automod-create $GUILD "Anti-Spam" keyword:scam,free,nitro actions:BLOCK_MESSAGE,ALERT # 4. Create invite INVITE=$(./discord-admin.sh invite-create 123456789 maxUses:100 unique:true | jq -r '.code') echo "Server invite: discord.gg/$INVITE" # 5. Setup mod log ./discord-admin.sh modlog-set $GUILD 987654321 ``` ### Daily Moderation Routine ```bash #!/bin/bash # Daily server maintenance GUILD="123456789" [REDACTED_SECRET]" # Check audit logs for suspicious activity ./discord-admin.sh audit-logs $GUILD action:BAN_ADD --format pretty # Check mod log ./discord-admin.sh audit-logs $GUILD user:BOT_USER_ID --format pretty # List recent bans ./discord-admin.sh audit-logs $GUILD action:BAN_ADD limit:50 --format pretty # Prune old inactive members ./discord-admin.sh member-prune $GUILD 30 # Check for spammers ./discord-admin.sh automod-list $GUILD ``` --- ## 🔧 Troubleshooting ### Common Errors | Error | Solution | |-------|----------| | `401: Unauthorized` | Check your bot token | | `403: Forbidden` | Bot lacks permissions | | `404: Not Found` | Invalid channel/guild/role ID | | `429: Too Many Requests` | Wait, script handles this | | `50013: Missing Permissions` | Bot role is below target role | | `50001: Missing Access` | Bot can't see the channel | ### Debug Mode ```bash ./discord-admin.sh --debug <command> ``` --- ## 📝 Notes - **14-day limit**: Bulk delete only works on messages from the last 14 days - **Role hierarchy**: Bot role must be higher than target roles - **Ownership**: Some operations require server owner - **Vanity URLs**: Require `DISCOVERABLE` feature and boosts - **Templates**: Only available to users with `MANAGE_GUILD` - **Audit logs**: Only viewable by bots with `VIEW_AUDIT_LOG`, retention is 90 days --- ## 🤖 Supported API Endpoints - Guilds & Guild Members - Channels & Threads - Roles & Permissions - Messages & Reactions - AutoModeration Rules - Webhooks - Invites & Vanity URLs - Guild Templates - Emojis & Stickers - Guild Scheduled Events - Stage Instances - Soundboard Sounds - Audit Logs - Integrations - Guild Widgets - Application Commands (partial)

path: discord-admin.sh
content: #!/bin/bash
# Discord Server Admin Pro - Complete CLI
# Full A-Z Discord server management

set -e

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'

# Config
BOT_TOKEN="${DISCORD_BOT_TOKEN:-}"
GUILD_ID="${DISCORD_GUILD_ID:-}"
API_BASE="https://discord.com/api/v10"

log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; exit 1; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*" >&2; }
log_success() { echo -e "${GREEN}[OK]${NC} $*"; }

# Check deps
check_deps() {
    command -v curl &> /dev/null || { log_error "curl required"; }
    command -v jq &> /dev/null || { log_error "jq required (sudo apt install jq)"; }
}

validate_token() { [[ -z "$BOT_TOKEN" ]] && log_error "DISCORD_BOT_TOKEN not set"; }

# API wrapper
api() {
    local method=$1 endpoint=$2 data=$3
    local response=$(curl -s -w "\n%{http_code}" -X "$method" \
        "$API_BASE$endpoint" \
        -H "Authorization: Bot $BOT_TOKEN" \
        -H "Content-Type: application/json" \
        ${data:+-d "$data"})
    
    local code=$(echo "$response" | tail -n1)
    local body=$(echo "$response" | sed '$d')
    
    case $code in
        200|201|204) echo "$body" ;;
        401) log_error "Unauthorized - check bot token" ;;
        403) log_error "Forbidden - bot lacks permissions" ;;
        404) log_error "Not found - check IDs" ;;
        429) local retry=$(echo "$body" | jq -r '.retry_after // 1'); log_warn "Rate limited, waiting ${retry}s"; sleep $retry; api $method $endpoint "$data" ;;
        *) log_error "API error $code: $body" ;;
    esac
}

api_get() { api GET "$1" ""; }
api_post() { api POST "$1" "$2"; }
api_patch() { api PATCH "$1" "$2"; }
api_delete() { api DELETE "$1" ""; }
api_put() { api PUT "$1" "${2:-}"; }

# JSON helpers
json_obj() { jq -n "$1" 2>/dev/null; }
kv_json() { local o="{}"; for a in "$@"; do [[ "$a" =~ ^([^:]+):(.+)$ ]] && o=$(echo "$o" | jq --arg k "${BASH_REMATCH[1]}" --arg v "${BASH_REMATCH[2]}" '. + {($k):$v}'); done; echo "$o"; }

# Duration parser (1h, 1d, etc)
parse_dur() {
    local d=$1 s=0
    [[ $d =~ ^([0-9]+)s$ ]] && s=${BASH_REMATCH[1]}
    [[ $d =~ ^([0-9]+)m$ ]] && s=$((${BASH_REMATCH[1]}*60))
    [[ $d =~ ^([0-9]+)h$ ]] && s=$((${BASH_REMATCH[1]}*3600))
    [[ $d =~ ^([0-9]+)d$ ]] && s=$((${BASH_REMATCH[1]}*86400))
    echo $s
}

# ============================================================================
# COMMANDS
# ============================================================================

show_help() {
    cat << 'EOF'
Discord Server Admin Pro - Full Server Management

USAGE: ./discord-admin.sh <command> [options]

SERVER INTELLIGENCE:
  server-info <guild>              Full server overview
  vanity-get <guild>              Get vanity URL
  vanity-set <guild> <code>       Set vanity URL
  widget-get <guild>              Get widget settings
  widget-edit <guild> <json>      Edit widget

CHANNELS:
  channel-list <guild>           List all channels
  channel-create <guild> <name> [type]  Create channel (text|voice|category|forum|stage)
  channel-edit <guild> <channelId> <json>  Edit channel
  channel-delete <guild> <channelId>     Delete channel
  channel-perms <guild> <channelId>       List permissions

ROLES:
  role-list <guild>              List all roles
  role-create <guild> <name> [json]  Create role with permissions
  role-edit <guild> <roleId> <json>   Edit role
  role-delete <guild> <roleId>   Delete role
  role-position <guild> <roleId> <pos>  Change position
  role-assign <guild> <roleId> <userId>  Assign role
  role-remove <guild> <roleId> <userId>  Remove role
  role-bulk <guild> <roleId> <userIds>   Bulk assign role

MEMBERS:
  member-info <guild> <userId>   Member details
  member-nick <guild> <userId> <nick>  Set nickname
  member-nick-reset <guild> <userId>   Reset nickname
  member-timeout <guild> <userId> <dur>  Timeout (1s,1m,1h,1d)
  member-untimeout <guild> <userId>  Remove timeout
  member-kick <guild> <userId> [reason]  Kick member
  member-ban <guild> <userId> [reason] [days]  Ban member
  member-unban <guild> <userId> [reason]  Unban member
  ban-list <guild>                List all bans
  prune <guild> [days]            Prune inactive members

MESSAGES:
  msg-send <channel> <content>   Send message
  msg-embed <channel> <json>     Send embed
  msg-edit <channel> <msgId> <content>  Edit message
  msg-delete <channel> <msgId>   Delete message
  msg-bulk-delete <channel> <msgIds>  Bulk delete (comma-sep)
  msg-history <channel> [limit]  Get message history
  msg-pin <channel> <msgId>       Pin message
  msg-unpin <channel> <msgId>     Unpin message
  msg-pins <channel>              List pins
  msg-search <guild> <query> [channel]  Search messages

AUTOMOD:
  automod-list <guild>           List AutoMod rules
  automod-create <guild> <name> <json>  Create rule
  automod-edit <guild> <ruleId> <json>   Edit rule
  automod-delete <guild> <ruleId> Delete rule

WEBHOOKS:
  webhook-list <guild> [channel]  List webhooks
  webhook-create <channel> <name> [avatar]  Create webhook
  webhook-info <webhookId>        Get webhook
  webhook-edit <webhookId> <json>  Edit webhook
  webhook-delete <webhookId>      Delete webhook
  webhook-exec <webhookId> <content> [json]  Execute webhook

EMOJIS & STICKERS:
  emoji-list <guild>              List emojis
  emoji-create <guild> <name> <imageUrl>  Add emoji
  emoji-delete <guild> <emojiId>   Delete emoji
  sticker-list <guild>            List stickers
  sticker-create <guild> <name> <tags> <imageUrl>  Add sticker
  sticker-edit <guild> <stickerId> <json>  Edit sticker
  sticker-delete <guild> <stickerId>  Delete sticker

EVENTS:
  event-list <guild>              List scheduled events
  event-create <guild> <json>     Create event
  event-edit <guild> <eventId> <json>  Edit event
  event-delete <guild> <eventId>   Delete event

INVITES:
  invite-list <guild>              List invites
  invite-create <channel> [json]   Create invite
  invite-info <code>              Get invite info
  invite-delete <guild> <code>    Delete invite

THREADS:
  thread-list <guild> [channel]   List threads
  thread-create <channel> <name> [msgId]  Create thread
  thread-edit <threadId> <json>     Edit thread
  thread-delete <threadId>          Delete thread
  thread-archive <threadId>         Archive thread
  thread-join <threadId>            Join thread
  thread-leave <threadId>           Leave thread

AUDIT LOGS:
  audit-logs <guild> [limit] [user] [action]  Get audit logs

STAGE:
  stage-create <channel> [topic]    Create stage instance
  stage-edit <channel> <json>       Edit stage
  stage-close <channel>             Close stage

INTEGRATIONS:
  integration-list <guild>          List integrations
  integration-sync <guild> <id>    Sync integration
  integration-delete <guild> <id>  Delete integration

TEMPLATES:
  template-list <guild>             List templates
  template-create <guild> <name> [desc]  Create template
  template-sync <guild> <code>      Sync template
  template-delete <guild> <id>      Delete template
  template-use <code> <name>        Create server from template

GUILD:
  guild-edit <guild> <json>        Edit server settings
  guild-leave <guild>              Leave server

MOD LOG:
  modlog-set <guild> <channel>      Set mod log channel
  modlog-get <guild>               Get mod log channel
  modlog-disable <guild>           Disable mod log

OPTIONS:
  --token <token>                   Set bot token
  --format <json|pretty|minimal>   Output format
  --help, -h                       Show this help

EXAMPLES:
  ./discord-admin.sh channel-list 123456789
  ./discord-admin.sh role-create 123456789 Moderator '{"color":16711680,"permissions":"268435456"}'
  ./discord-admin.sh member-ban 123456789 987654321 Spamming 7
  ./discord-admin.sh webhook-create 123456789 "Alerts" --token MYTOKEN

JSON FORMAT NOTES:
  - Use single quotes around JSON: '{"key":"value"}'
  - Permission values are integers (not names)
  - Colors are hex (e.g., "#FF0000" or "0xFF0000")
  - Timestamps: ISO 8601 format

PERMISSION VALUES:
  ADMINISTRATOR: 8
  VIEW_AUDIT_LOG: 128
  MANAGE_GUILD: 32
  MANAGE_ROLES: 268435456
  MANAGE_CHANNELS: 4
  KICK_MEMBERS: 2
  BAN_MEMBERS: 4
  MANAGE_MESSAGES: 8192
  MANAGE_WEBHOOKS: 536870912
  MANAGE_EMOJIS: 1073741824
  MANAGE_EVENTS: 8589934592
  MODERATE_MEMBERS: 274877906944

EOF
}

# ============================================================================
# MAIN
# ============================================================================

check_deps

# Parse global options
while [[ "$1" =~ ^-- ]]; do
    case "$1" in
        --token) BOT_TOKEN="$2"; shift 2 ;;
        --format) OUTPUT_FORMAT="$2"; shift 2 ;;
        --debug) DEBUG_MODE="true"; shift ;;
        *) shift ;;
    esac
done

cmd="${1:-}"
shift 2>/dev/null || true

case "$cmd" in
    --help|-h|"") show_help ;;
    
    # Server
    server-info) validate_token; api_get "/guilds/${1:-$GUILD_ID}?with_counts=true" ;;
    vanity-get) validate_token; api_get "/guilds/${1:-$GUILD_ID}/vanity-url" ;;
    vanity-set) validate_token; api_patch "/guilds/$1/vanity-url" "{\"code\":\"$2\"}" ;;
    widget-get) validate_token; api_get "/guilds/${1:-$GUILD_ID}/widget" ;;
    widget-edit) validate_token; api_patch "/guilds/$1/widget" "$2" ;;
    guild-edit) validate_token; api_patch "/guilds/$1" "$2" ;;
    guild-leave) validate_token; api_delete "/guilds/${1:-$GUILD_ID}/members/@me" ;;
    
    # Channels
    channel-list) validate_token; api_get "/guilds/${1:-$GUILD_ID}/channels" ;;
    channel-create) validate_token; 
        type=${3:-text}; t=0; [[ "$type" == "voice" ]] && t=2; [[ "$type" == "category" ]] && t=4; [[ "$type" == "forum" ]] && t=15; [[ "$type" == "stage" ]] && t=13
        api_post "/guilds/$1/channels" "{\"name\":\"$2\",\"type\":$t}" ;;
    channel-edit) validate_token; api_patch "/channels/$1" "$2" ;;
    channel-delete) validate_token; api_delete "/channels/$1" ;;
    channel-perms) validate_token; api_get "/channels/$1/permissions" ;;
    channel-sync) validate_token; api_patch "/channels/$2" "{\"permissions_sync\":true}" ;;
    
    # Roles
    role-list) validate_token; api_get "/guilds/${1:-$GUILD_ID}/roles" ;;
    role-create) validate_token; api_post "/guilds/${1:-$GUILD_ID}/roles" "{\"name\":\"$2\"${3:+,\"$3}}\"" ;;
    role-edit) validate_token; api_patch "/guilds/$1/roles/$2" "$3" ;;
    role-delete) validate_token; api_delete "/guilds/$1/roles/$2" ;;
    role-position) validate_token; api_patch "/guilds/$1/roles" "[{\"id\":\"$2\",\"position\":$3}]" ;;
    role-assign) validate_token; api_put "/guilds/$1/members/$3/roles/$2" ;;
    role-remove) validate_token; api_delete "/guilds/$1/members/$3/roles/$2" ;;
    role-bulk) 
        validate_token; IFS=',' read -ra users <<< "$3"
        for u in "${users[@]}"; do api_put "/guilds/$1/members/$u/roles/$2" 2>/dev/null || true; done
        log_success "Role assigned to ${#users[@]} users" ;;
    
    # Members
    member-info) validate_token; api_get "/guilds/${1:-$GUILD_ID}/members/$2" ;;
    member-nick) validate_token; api_patch "/guilds/${1:-$GUILD_ID}/members/$2" "{\"nick\":\"$3\"}" ;;
    member-nick-reset) validate_token; api_patch "/guilds/${1:-$GUILD_ID}/members/$2" "{\"nick\":null}" ;;
    member-timeout)
        validate_token; s=$(parse_dur "$3")
        t=$(date -d "+$s sec" -Iseconds 2>/dev/null || date -u -v+"${s}S" -Iseconds 2>/dev/null || echo "")
        [[ -z "$t" ]] && t=$(date -u +%Y-%m-%dT%H:%M:%SZ)
        api_patch "/guilds/${1:-$GUILD_ID}/members/$2" "{\"communication_disabled_until\":\"$t\"}" ;;
    member-untimeout) validate_token; api_patch "/guilds/${1:-$GUILD_ID}/members/$2" "{\"communication_disabled_until\":null}" ;;
    member-kick) validate_token; [[ -n "$3" ]] && api_delete "/guilds/${1:-$GUILD_ID}/members/$2" "{\"reason\":\"$3\"}" || api_delete "/guilds/${1:-$GUILD_ID}/members/$2" ;;
    member-ban) validate_token; d=${4:-0}; api_put "/guilds/${1:-$GUILD_ID}/bans/$2" "{\"delete_message_days\":$d${3:+,\"reason\":\"$3\"}}" ;;
    member-unban) validate_token; api_delete "/guilds/${1:-$GUILD_ID}/bans/$2" ;;
    ban-list) validate_token; api_get "/guilds/${1:-$GUILD_ID}/bans" ;;
    prune) validate_token; api_post "/guilds/${1:-$GUILD_ID}/prune" "{\"days\":${2:-30}}" ;;
    
    # Messages
    msg-send) validate_token; api_post "/channels/$1/messages" "{\"content\":\"$2\"}" ;;
    msg-embed) validate_token; api_post "/channels/$1/messages" "{\"embeds\":[$2]}" ;;
    msg-edit) validate_token; api_patch "/channels/$1/messages/$2" "{\"content\":\"$3\"}" ;;
    msg-delete) validate_token; api_delete "/channels/$1/messages/$2" ;;
    msg-bulk-delete) 
        validate_token; IFS=',' read -ra msgs <<< "$2"
        ids=$(printf '"%s",' "${msgs[@]}"); ids="${ids%,}"
        api_post "/channels/$1/messages/bulk-delete" "{\"messages\":[$ids]}" ;;
    msg-history) validate_token; api_get "/channels/$1/messages?limit=${2:-100}" ;;
    msg-pin) validate_token; api_put "/channels/$1/pins/$2" ;;
    msg-unpin) validate_token; api_delete "/channels/$1/pins/$2" ;;
    msg-pins) validate_token; api_get "/channels/$1/pins" ;;
    msg-search) validate_token; api_get "/guilds/${1:-$GUILD_ID}/messages/search?content=$2${3:+&channel_id=$3}" ;;
    
    # AutoMod
    automod-list) validate_token; api_get "/guilds/${1:-$GUILD_ID}/auto-moderation/rules" ;;
    automod-create) validate_token; api_post "/guilds/${1:-$GUILD_ID}/auto-moderation/rules" "$2" ;;
    automod-edit) validate_token; api_patch "/guilds/$1/auto-moderation/rules/$2" "$3" ;;
    automod-delete) validate_token; api_delete "/guilds/${1:-$GUILD_ID}/auto-moderation/rules/$2" ;;
    
    # Webhooks
    webhook-list) validate_token; api_get "/guilds/${1:-$GUILD_ID}/webhooks${2:+/$2}" ;;
    webhook-create) validate_token; api_post "/channels/${1:-$GUILD_ID}/webhooks" "{\"name\":\"$2\"}" ;;
    webhook-info) validate_token; api_get "/webhooks/$1" ;;
    webhook-edit) validate_token; api_patch "/webhooks/$1" "$2" ;;
    webhook-delete) validate_token; api_delete "/webhooks/$1" ;;
    webhook-exec) 
        validate_token; shift
        id=$1; shift; content=$1; shift
        data="{\"content\":\"$content\"}"
        for a in "$@"; do data=$(echo "$data" | jq --argjson v "$a" '. + $v'); done
        api_post "/webhooks/$id" "$data" ;;
    
    # Emojis & Stickers
    emoji-list) validate_token; api_get "/guilds/${1:-$GUILD_ID}/emojis" ;;
    emoji-create) validate_token; api_post "/guilds/${1:-$GUILD_ID}/emojis" "{\"name\":\"$2\",\"image\":\"$3\"}" ;;
    emoji-delete) validate_token; api_delete "/guilds/${1:-$GUILD_ID}/emojis/$2" ;;
    sticker-list) validate_token; api_get "/guilds/${1:-$GUILD_ID}/stickers" ;;
    sticker-create) validate_token; api_post "/guilds/${1:-$GUILD_ID}/stickers" "{\"name\":\"$2\",\"tags\":\"$3\"}" ;;
    sticker-edit) validate_token; api_patch "/guilds/${1:-$GUILD_ID}/stickers/$2" "$3" ;;
    sticker-delete) validate_token; api_delete "/guilds/${1:-$GUILD_ID}/stickers/$2" ;;
    
    # Events
    event-list) validate_token; api_get "/guilds/${1:-$GUILD_ID}/scheduled-events" ;;
    event-create) validate_token; api_post "/guilds/${1:-$GUILD_ID}/scheduled-events" "$2" ;;
    event-edit) validate_token; api_patch "/guilds/$1/scheduled-events/$2" "$3" ;;
    event-delete) validate_token; api_delete "/guilds/${1:-$GUILD_ID}/scheduled-events/$2" ;;
    
    # Invites
    invite-list) validate_token; api_get "/guilds/${1:-$GUILD_ID}/invites" ;;
    invite-create) 
        validate_token; c=$1; shift
        data="{}"; for a in "$@"; do data=$(echo "$data" | jq --argjson v "$a" '. + $v'); done
        api_post "/channels/$c/invites" "$data" ;;
    invite-info) validate_token; api_get "/invites/$1" ;;
    invite-delete) validate_token; api_delete "/guilds/${1:-$GUILD_ID}/invites/$2" ;;
    
    # Threads
    thread-list) validate_token; [[ -n "$2" ]] && api_get "/channels/$2/threads" || api_get "/guilds/${1:-$GUILD_ID}/threads" ;;
    thread-create) 
        validate_token; [[ -n "$3" ]] && api_post "/channels/$1/messages/$3/threads" "{\"name\":\"$2\"}" \
        || api_post "/channels/$1/threads" "{\"name\":\"$2\"}" ;;
    thread-edit) validate_token; api_patch "/channels/$1" "$2" ;;
    thread-delete) validate_token; api_delete "/channels/$1" ;;
    thread-archive) validate_token; api_patch "/channels/$1" "{\"archived\":true}" ;;
    thread-join) validate_token; api_post "/channels/$1/thread-members/@me" ;;
    thread-leave) validate_token; api_delete "/channels/$1/thread-members/@me" ;;
    
    # Audit Logs
    audit-logs) 
        validate_token; e="/guilds/${1:-$GUILD_ID}/audit-logs?limit=${2:-50}"
        [[ -n "$3" ]] && e+="&user_id=$3"; [[ -n "$4" ]] && e+="&action_type=$4"
        api_get "$e" ;;
    
    # Stage
    stage-create) validate_token; api_post "/channels/$1/threads" "{\"name\":\"${2:-Stage}\",\"type\":13}" ;;
    stage-edit) validate_token; api_patch "/channels/$1" "$2" ;;
    stage-close) validate_token; api_patch "/channels/$1" "{\"archived\":true}" ;;
    
    # Integrations
    integration-list) validate_token; api_get "/guilds/${1:-$GUILD_ID}/integrations" ;;
    integration-sync) validate_token; api_post "/guilds/${1:-$GUILD_ID}/integrations/$2" ;;
    integration-delete) validate_token; api_delete "/guilds/${1:-$GUILD_ID}/integrations/$2" ;;
    
    # Templates
    template-list) validate_token; api_get "/guilds/${1:-$GUILD_ID}/templates" ;;
    template-create) validate_token; api_post "/guilds/${1:-$GUILD_ID}/templates" "{\"name\":\"$2\"${3:+,\"description\":\"$3\"}}" ;;
    template-sync) validate_token; api_put "/guilds/${1:-$GUILD_ID}/templates/$2" ;;
    template-delete) validate_token; api_delete "/guilds/${1:-$GUILD_ID}/templates/$2" ;;
    template-use) validate_token; api_post "/guilds/$1/templates" "{\"name\":\"$2\"}" ;;
    
    # Mod Log
    modlog-set) validate_token; api_patch "/guilds/$1" "{\"system_channel_id\":\"$2\"}" ;;
    modlog-get) validate_token; api_get "/guilds/${1:-$GUILD_ID}" | jq '.system_channel_id' ;;
    modlog-disable) validate_token; api_patch "/guilds/${1:-$GUILD_ID}" "{\"system_channel_id\":null}" ;;
    
    *)
        log_error "Unknown command: $cmd"
        echo "Use --help for available commands"
        exit 1
        ;;
esac

# Output format
if [[ -t 1 ]]; then
    if [[ "$OUTPUT_FORMAT" == "pretty" ]] || [[ -z "$OUTPUT_FORMAT" && "$cmd" != "msg-send" && "$cmd" != "member-kick" ]]; then
        if command -v jq &> /dev/null; then
            while IFS= read -r line; do echo "$line"; done | jq '.' 2>/dev/null || true
        fi
    fi
fi


path: discord-ctrl.sh
content: #!/bin/bash
# Discord Server Control - CLI Wrapper
# Usage: ./discord-ctrl.sh <command> [options]

set -e

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Config
BOT_TOKEN="${DISCORD_BOT_TOKEN:-}"
GUILD_ID="${DISCORD_GUILD_ID:-}"

# Help
show_help() {
    cat << EOF
Discord Server Control - Full Server Management

Commands:
    channel-list [guildId]              List all channels
    channel-create <guildId> <name> [type]  Create a channel (type: text|voice|category)
    channel-delete <guildId> <channelId>    Delete a channel
    channel-edit <guildId> <channelId> <name>    Edit channel name
    
    role-list <guildId>                  List all roles
    role-create <guildId> <name> [color]     Create a role
    role-delete <guildId> <roleId>           Delete a role
    
    member-kick <guildId> <userId> [reason]  Kick a member
    member-ban <guildId> <userId> [reason]   Ban a member
    member-unban <guildId> <userId>          Unban a user
    
    message-send <guildId> <channelId> <message>   Send a message
    message-delete <guildId> <messageId>           Delete a message
    
    server-info <guildId>                 Get server info
    emoji-list <guildId>                   List server emojis

Options:
    --token <token>       Bot token (or set DISCORD_BOT_TOKEN)
    --help                Show this help

Examples:
    ./discord-ctrl.sh channel-list 123456789
    ./discord-ctrl.sh channel-create 123456789 general text
    ./discord-ctrl.sh member-kick 123456789 987654321 Spam
    ./discord-ctrl.sh message-send 123456789 111222333 "Hello world!"

EOF
}

# API calls
api_call() {
    local method="$1"
    local endpoint="$2"
    local data="$3"
    
    curl -s -X "$method" \
        "https://discord.com/api/v10$endpoint" \
        -H "Authorization: Bot $BOT_TOKEN" \
        -H "Content-Type: application/json" \
        ${data:+-d "$data"}
}

# Commands
cmd_channel_list() {
    local guild="${1:-$GUILD_ID}"
    api_call "GET" "/guilds/$guild/channels" | jq '.[] | "\(.name) [\(?.type)]"' 2>/dev/null || api_call "GET" "/guilds/$guild/channels"
}

cmd_channel_create() {
    local guild="$1" name="$2" type="${3:-text}"
    local data=$(jq -n --arg n "$name" --arg t "$type" '{name:$n, type:($t | if .=="voice" then 2 elif .=="category" then 4 else 0 end)}')
    api_call "POST" "/guilds/$guild/channels" "$data"
}

cmd_channel_delete() {
    local guild="$1" channel="$2"
    api_call "DELETE" "/channels/$channel"
}

cmd_channel_edit() {
    local guild="$1" channel="$2" name="$3"
    local data=$(jq -n --arg n "$name" '{name:$n}')
    api_call "PATCH" "/channels/$channel" "$data"
}

cmd_role_list() {
    local guild="${1:-$GUILD_ID}"
    api_call "GET" "/guilds/$guild/roles" | jq '.[] | "\(.name) - \(.id)"' 2>/dev/null || api_call "GET" "/guilds/$guild/roles"
}

cmd_role_create() {
    local guild="$1" name="$2" color="${3:-000000}"
    local data=$(jq -n --arg n "$name" --arg c "$color" '{name:$n, color:("0x"+$c | tonumber)}')
    api_call "POST" "/guilds/$guild/roles" "$data"
}

cmd_role_delete() {
    local guild="$1" role="$2"
    api_call "DELETE" "/guilds/$guild/roles/$role"
}

cmd_member_kick() {
    local guild="$1" user="$2" reason="${3:-}"
    local data=$(jq -n ${reason:+--arg r "$reason" '{reason:$r}'})
    api_call "DELETE" "/guilds/$guild/members/$user" "${reason:+$data}"
}

cmd_member_ban() {
    local guild="$1" user="$2" reason="${3:-}"
    local data=$(jq -n ${reason:+--arg r "$reason" '{reason:$r}'})
    api_call "PUT" "/guilds/$guild/bans/$user" "${reason:+$data}"
}

cmd_member_unban() {
    local guild="$1" user="$2"
    api_call "DELETE" "/guilds/$guild/bans/$user"
}

cmd_message_send() {
    local guild="$1" channel="$2" message="$3"
    local data=$(jq -n --arg m "$message" '{content:$m}')
    api_call "POST" "/channels/$channel/messages" "$data"
}

cmd_message_delete() {
    local guild="$1" message="$2"
    api_call "DELETE" "/channels/$guild/messages/$message"
}

cmd_server_info() {
    local guild="${1:-$GUILD_ID}"
    api_call "GET" "/guilds/$guild?with_counts=true"
}

cmd_emoji_list() {
    local guild="${1:-$GUILD_ID}"
    api_call "GET" "/guilds/$guild/emojis"
}

# Main
main() {
    if [[ -z "$BOT_TOKEN" ]]; then
        echo -e "${RED}Error: DISCORD_BOT_TOKEN not set. Use --token or export DISCORD_BOT_TOKEN${NC}"
        exit 1
    fi
    
    local cmd="${1:-}"
    shift || true
    
    case "$cmd" in
        channel-list)  cmd_channel_list "$@" ;;
        channel-create) cmd_channel_create "$@" ;;
        channel-delete) cmd_channel_delete "$@" ;;
        channel-edit)   cmd_channel_edit "$@" ;;
        role-list)      cmd_role_list "$@" ;;
        role-create)    cmd_role_create "$@" ;;
        role-delete)    cmd_role_delete "$@" ;;
        member-kick)    cmd_member_kick "$@" ;;
        member-ban)     cmd_member_ban "$@" ;;
        member-unban)   cmd_member_unban "$@" ;;
        message-send)   cmd_message_send "$@" ;;
        message-delete) cmd_message_delete "$@" ;;
        server-info)    cmd_server_info "$@" ;;
        emoji-list)     cmd_emoji_list "$@" ;;
        --help|-h)      show_help ;;
        "")             show_help ;;
        *)              echo -e "${RED}Unknown command: $cmd${NC}"; show_help; exit 1 ;;
    esac
}

main "$@"


Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (CRITICAL)