Username
The `username` command allows users to update their displayed username in the bot's database. This is separate from their Discord username and appears in various bot features and profile displays.
Command Details
- Name: username
- Aliases: user
- Category: Profile
- Description: Change your username in the bot's database
- Usage:
P username <new_username>
,p username <new_username>
, or/username <new_username>
- Examples:
P username CoolUser123
p user MyNewName
/username AwesomeGamer
- Cooldown: 60 seconds (1 minute)
- Arguments: new_username (required)
- Slash Command: Enabled
- Permissions:
- Bot: SendMessages, ViewChannel
- User: None
- Player Requirements: None (no voice, DJ, or active player required)
Functionality
- Username Updates: Allows users to set a custom display name stored in the bot's database.
- Username Validation: Enforces length limits and content restrictions for usernames.
- Database Integration: Updates the user's profile document with the new username.
- Immediate Feedback: Provides instant confirmation when username is successfully changed.
- Error Handling: Returns appropriate error messages for invalid usernames or system failures.
- Cooldown Protection: Prevents spam by enforcing a 60-second cooldown between username changes.
- Case Sensitivity: Preserves the exact case of the provided username.
- Unicode Support: Accepts special characters and emoji in usernames (subject to validation).
- Profile Integration: Updated username immediately reflects in profile displays and other bot features.
- Persistent Storage: Username changes are permanently saved to MongoDB database.
- Slash Command Support: Available through both traditional prefix commands and Discord slash commands.
- Real-time Updates: Changes take effect immediately across all bot systems.
Code Overview
The command is built using a Command
class structure and handles both message-based and interaction-based (slash command) inputs. It uses:
client.db.users.updateOne()
to modify the user's database document with the new username.- Input validation to ensure the username meets required criteria and length limits.
args.join(' ')
to handle multi-word usernames by combining all arguments.- Error handling for database connection issues and update failures.
- Cooldown management using the command framework's built-in cooldown system.
- Success confirmation messages sent back to the user upon successful update.
- Database query optimization to update only the username field rather than entire document.
- Sanitization of input to prevent potential database injection or formatting issues.
- Integration with the bot's user profile system for immediate effect across features.
- Support for both traditional message commands and modern Discord slash command interactions.
- Proper error messaging for edge cases like empty usernames or system unavailability.
- Logging of username changes for administrative tracking and debugging purposes.
Profile
The `profile` command displays comprehensive user profile information with custom visual cards and special themes. It can be triggered using the prefixes `P`, `p`, or the slash command `/`.
Leaderboard
The `leaderboard` command displays rankings for various metrics within a Discord guild and globally, such as coin balance, spent coins, and streaks for specific activities. It can be triggered using the prefixes `P`, `p`, or the slash command `/`.