Message & Channel Events
Relevant source files
The following files were used as context for generating this wiki page:
The Message and Channel event systems within the Poixpixel Discord Bot are responsible for monitoring, processing, and logging activities occurring within text and voice channels. This system encompasses specialized logic for features like counting games, automated message auditing (deletions and edits), and channel management tracking (creation, deletion, and permission updates).
These events are central to the bot's moderation and utility functions, ensuring that all interactions are either validated against game rules or recorded for administrative review. The architecture relies on Discord.js gateways to receive events, which are then routed to specialized managers or logging utilities.
Sources: src/discord-bot.ts:80-90, src/util/logging/logAction.ts:28-40
Message Event Processing
Message events are handled primarily through content validation and auditing. The bot specifically monitors message creation for the counting game and audits message mutations (edits and deletions) for server logging.
Message Auditing and Logging
When a message is deleted or edited, the bot captures the event to maintain an audit trail in the designated log channel. The system distinguishes between individual deletions, bulk purges, and content modifications.
The logging system extracts the author, channel, and content. For edits, it specifically compares oldContent and newContent to show changes. For purges, it generates a temporary .txt file containing the history of all removed messages before clearing the local cache.
Sources: src/util/logging/logAction.ts:114-140, src/util/logging/logAction.ts:241-267
Counting Game Logic
The counting system is a specialized message event handler that triggers when a message is sent in the configured counting channel. It validates if the message content matches the expected sequence and if the user is eligible to count.
| Feature | Description |
|---|---|
| Validation | Ensures the message content is a valid number and matches currentCount + 1. |
| Double-Count Prevention | Prevents the same user from counting two numbers in a row. |
| Mistake Tracking | Tracks errors; exceeding thresholds leads to warnings or counting bans. |
| Rollback Mechanism | If the count is > 100, a mistake rolls back to the nearest magnitude (e.g., 100, 200). |
Sources: src/util/counting/countingManager.ts:182-250, src/util/counting/countingManager.ts:503-530
Channel and Role Management Events
Channel events track structural changes within the Discord server, including creation, deletion, and permission overrides.
Channel Lifecycle Tracking
The bot monitors channelCreate, channelDelete, and channelUpdate events. These are processed by the logAction utility to notify administrators of changes.
Permission auditing is granular; the system compares the old and new bitfields to identify specific permission strings (e.g., SEND_MESSAGES, MANAGE_CHANNELS) that were toggled.
Sources: src/util/logging/logAction.ts:391-450, src/util/logging/logAction.ts:522-545
Logging Configuration
The behavior of these events is governed by the config.json file, which defines where logs are sent and how specialized channels are identified.
| Configuration Key | Type | Description |
|---|---|---|
channels.logs | Snowflake | The ID of the channel where audit logs are sent. |
channels.counting | Snowflake | The ID of the channel where the counting game is active. |
counting.mistakeThreshold | Number | Number of mistakes allowed before a warning is issued. |
counting.maxWarnings | Number | Maximum warnings before an auto-ban from counting occurs. |
Sources: config.example.json:62-75, config.example.json:100-115
Technical Implementation Details
Validation Helpers
The system uses a validateInteraction helper to ensure that events are processed only if they occur within a guild and have valid channel context. This prevents the bot from attempting to log or process events from Direct Messages where server-specific logic (like counting or audit logging) is inapplicable.
export async function validateInteraction(interaction: Interaction): Promise<boolean> {
if (!interaction.inGuild()) return false;
if (!interaction.channel) return false;
// ... verification logic
return true;
}
Sources: src/util/helpers.ts:474-489
Error Handling in Events
Because message and channel events occur frequently, the bot implements a robust error-handling strategy. Failures in logging or processing (such as a missing log channel or API rate limits) are caught and logged to the internal Winston logger rather than crashing the bot instance.
Sources: src/discord-bot.ts:93-115, src/util/logging/logAction.ts:31-36
Summary
The Message & Channel Events system provides the backbone for both server engagement (through counting) and server security (through auditing). By centralizing logic in the logAction utility and countingManager, the bot maintains a clear separation between event reception and business logic execution.