Member Event Processors
Relevant source files
The following files were used as context for generating this wiki page:
Member Event Processors are a core component of TrackerBot responsible for managing the lifecycle of Discord guild members. This system automates essential administrative tasks such as assigning initial roles, delivering welcome messages, and cleaning up temporary data when members leave the server.
The system is primarily event-driven, leveraging the discord.js library to listen for GuildMemberAdd and GuildMemberRemove events. By centralizing these actions in dedicated handlers, the bot ensures a consistent onboarding experience and maintains server organization without manual intervention.
Sources: src/handlers/memberHandlers.js:1-20, AGENTS.md:15-20
Architecture and Integration
Member handlers are initialized during the bot's bootstrap phase. The bot.js entry point calls registerMemberHandlers(client), which attaches specific logic to the Discord client instance.
The diagram above illustrates the registration and execution flow of member-related event listeners within the bot.
Member Join Logic
When a new user joins the guild, the processor executes two primary workflows: role synchronization and community onboarding.
Automated Role Assignment
The assignJoinRoles function attempts to grant a set of predefined roles to the new member. It first looks for a role named "user" (case-insensitive) within the guild's cache. Additionally, it retrieves four mandatory auto-role IDs from the environment configuration.
| Config Variable | Purpose | Requirement |
|---|---|---|
AUTO_ROLE_ID_1 | Primary auto-assigned role | Required |
AUTO_ROLE_ID_2 | Secondary auto-assigned role | Required |
AUTO_ROLE_ID_3 | Tertiary auto-assigned role | Required |
AUTO_ROLE_ID_4 | Quaternary auto-assigned role | Required |
Sources: src/handlers/memberHandlers.js:25-50, src/config/env.js
Onboarding and Welcome Messages
The system sends a personalized welcome message to a specific channel identified by WELCOME_CHANNEL_ID. To facilitate later cleanup, the bot maintains an in-memory Map called welcomeMessages, which links the member.id to the specific message.id sent.
Sequence of events during the welcome message generation and tracking process.
Sources: src/handlers/memberHandlers.js:53-64
Member Leave and Cleanup
To prevent the welcome channel from becoming cluttered with messages for users who are no longer in the server, the processor implements a cleanup routine.
Message Deletion Routine
When a GuildMemberRemove event is triggered, the cleanupWelcomeMessage function is called.
- It retrieves the
messageIdassociated with the member's ID from thewelcomeMessagesmap. - If found, it fetches the message from the Discord API and deletes it.
- The entry is removed from the in-memory map regardless of whether the API deletion succeeded.
Note: Because the welcomeMessages map is stored in volatile memory, any welcome messages sent before a bot restart cannot be automatically cleaned up when those members leave.
Sources: src/handlers/memberHandlers.js:6-11, src/handlers/memberHandlers.js:66-83
Bulk Member Management
Beyond individual event processing, the system provides administrative tools for managing existing members through slash commands.
The put-member-role Command
This command allows administrators to perform a bulk update on all guild members who may have missed the auto-role assignment (specifically AUTO_ROLE_ID_4).
- Permissions: Requires the role ID specified in
PANEL_ADMIN_ROLE_ID. - Logic:
- Fetches all guild members.
- Filters for members who are not bots and do not currently possess the target role.
- Iteratively adds the role to each identified member.
- Provides a summary report of successful and failed assignments.
Sources: src/interactions/slashHandlers.js:124-206, src/commands/registerSlashCommands.js:23-24
Security and Spam Prevention (Honeypot)
The member processing ecosystem includes a "Honeypot" system designed to protect the community from automated spam bots.
Operation
The bot monitors a specific channel (HONEYPOT_CHANNEL_ID). Real members are warned not to post there via a pinned-style message. Any non-bot member (excluding those with the ADMIN_ROLE_ID) who sends a message in this channel is immediately:
- Subject to message deletion.
- Banned from the guild (with a fallback to "Kick" if ban permissions are insufficient).
Sources: src/handlers/honeypotHandler.js:10-25, src/handlers/honeypotHandler.js:47-66
Summary
Member Event Processors provide the foundational automation required to manage the TarkovTracker Discord community. By combining reactive event listeners (join/leave) with proactive administrative commands (bulk role assignment) and defensive measures (honeypot), the system maintains server order and ensures that only authorized users receive the necessary access roles.
Sources: src/handlers/memberHandlers.js, src/interactions/slashHandlers.js, src/handlers/honeypotHandler.js