Information
Stats
The `stats` command displays comprehensive statistics about the bot in a Discord server. It can be triggered using the prefixes `P`, `p`, or the slash command `/`.
Command Details
- Name: stats
- Aliases: botstats, statistics
- Category: Information
- Description: Displays statistics about the bot
- Usage:
P stats,p stats, or/stats - Examples:
P statsp stats/stats
- Cooldown: 5 seconds
- Arguments: None
- Slash Command: Enabled
- Permissions:
- Bot: SendMessages, ViewChannel, EmbedLinks
- User: None
- Player Requirements: None (no voice, DJ, or active player required)
Functionality
- Displays comprehensive bot statistics in an organized embed format.
- Shows a loading message while gathering statistical data.
- Fetches data from the database to provide accurate user counts.
- Displays an embed with:
- A title with customizable emojis showing "STATS".
- Total number of servers the bot is in.
- Total number of registered users (from database) or cached users.
- Bot uptime formatted in days, hours, and minutes.
- Arrow emojis for visual formatting throughout the fields.
- A footer with additional information.
- Includes interactive buttons:
- Support button linking to the support server.
- Invite button for adding the bot to other servers.
- Supports both prefix-based (
Porp) and slash command (/) inputs. - Handles errors with appropriate error messages.
Code Overview
The command is built using a Command class structure and handles both message-based and interaction-based (slash command) inputs. It uses:
Users.find()to query the database for accurate user statistics.client.guilds.cache.sizeto get the total number of servers.client.users.cache.sizeas a fallback for user count if database query fails.client.channels.cache.sizeto count accessible channels.client.uptimewith mathematical calculations to format uptime into readable format.Math.floor()operations to convert milliseconds into days, hours, and minutes.client.embed()to create a formatted embed with statistical information.client.utils.linkButtonto create interactive buttons for support and invite links.client.utils.createButtonRowto organize buttons in a row layout.- Language localization for messages and statistical field formatting.
- Global emoji integration for visual enhancement and formatting.
- Loading states for better user experience during data gathering.
- Error handling for database queries and unexpected issues during execution.