Overview
Aphonos is built with TypeScript using Discord.js v14, featuring a modular command system and event-driven architecture. The bot is designed specifically for the ALTER EGO Wiki and Tower Defense Simulator Wiki Discord servers.Core Architecture
AltershaperBot Class
The main bot logic is encapsulated in theAltershaperBot class located in src/index.ts:25.
Key Components
1. Discord Client
The bot uses the Discord.jsClient class with the following intents:
- Guilds: Access to server information
- GuildMessages: Read and send messages
- MessageContent: Access message content (privileged intent)
- GuildMembers: Track member joins and member data
- GuildModeration: Handle kicks, bans, and timeouts
- GuildMessageReactions: Reaction role functionality
2. Command System
Commands are loaded vialoadCommands() from src/utils/commandLoader.ts:40 and stored in a Discord.js Collection for efficient lookup.
3. Event Listeners
Event listeners are registered insetupEventListeners() at src/index.ts:52:
Event Handlers
Event handlers are defined insrc/utils/eventHandlers.ts and handle the bot’s responses to Discord events.
Interaction Handler
Handles slash command interactions with permission checking (src/utils/eventHandlers.ts:21):
Member Join Handler
Sends welcome messages when new members join (src/utils/eventHandlers.ts:108):
Reaction Handlers
Handle reaction role functionality throughReactionRoleHandler (src/utils/eventHandlers.ts:130, src/utils/eventHandlers.ts:158).
Utility Systems
Command Loader
The command loader (src/utils/commandLoader.ts) imports and registers all commands:
Reaction Role Handler
Manages reaction roles for self-assignable roles via message reactions.Console Handler
Provides a command-line interface for bot administration, including commands likereload, status, restart, and shutdown.
Lock Manager
Manages battle locks to prevent users from engaging in multiple concurrent battles.Inter-Server Chat
Facilitates cross-server chat channels between linked Discord servers.Moderation Logger
Tracks all moderation actions with unique IDs (e.g., W1, K1, B1, T1, C1) for kicks, bans, timeouts, warnings, and message clears.Bot Lifecycle Methods
start()
Initializes the bot and logs in to Discord (src/index.ts:172):
registerSlashCommands()
Registers all slash commands globally with Discord (src/index.ts:149):
reloadSlashCommands()
Reloads commands without restarting the bot (src/index.ts:199).
restart()
Performs a full internal restart of the bot (src/index.ts:223).
shutdown()
Gracefully shuts down the bot (src/index.ts:217).
Technology Stack
- Runtime: Node.js with ES Modules
- Language: TypeScript 5.9+
- Discord Library: Discord.js v14.25+
- Target: ES2022
- Module System: ESNext with
.jsextensions in imports - Image Processing: Canvas for battle graphics and ship compatibility images
Project Structure
Environment Variables
The bot requires the following environment variable:DISCORD_TOKEN: Your Discord bot token from the Developer Portal
- Additional configuration may be needed for specific features like inter-server chat
Build System
The bot uses TypeScript compiler with the following configuration:- TypeScript compilation:
tsc - Asset copying: Image files for commands
- Output:
dist/directory