Utility
Clear
The `clear` command allows users to delete a specified number of messages in a Discord server. It can be triggered using the prefixes `P`, `p`, or the slash command `/`.
Clear Command
The clear command is a utility feature in a Discord bot that deletes a specified number of messages in a channel.
Command Details
- Name:
clear - Aliases:
purge,delete - Category: Utility
- Description: Deletes a specified number of messages (1-1000).
- Usage:
- Prefix:
P clear <number>,p clear <number> - Slash:
/clear [number_message_delete]
- Prefix:
- Examples:
P clear 10p clear 250/clear 100
- Cooldown: 3 seconds
- Arguments: Required (number of messages to delete)
- Slash Command: Enabled
- Permissions:
- Bot: ManageMessages
- User: ManageMessages or Administrator
- Player Requirements: None (no voice, DJ, or active player required)
Functionality
- Requires the user to have
ManageMessagesorAdministratorpermissions to execute. - Deletes a specified number of messages (between 1 and 1000) in the channel where the command is invoked.
- Sends a confirmation message indicating the number of messages deleted.
- Supports both prefix-based (
Porp) and slash command (/) inputs. - Deletes messages in chunks of up to 100 at a time for efficiency.
- If an invalid number (e.g., non-numeric, < 0, or > 1000) is provided or the user lacks permissions, an error message is displayed.
- For slash commands, the response is deferred with an ephemeral flag (visible only to the user).
Code Overview
The command is built using a Command class structure and handles both message-based and interaction-based (slash command) inputs. It uses:
ctx.channel.bulkDelete()to delete messages in batches of up to 100.ctx.member.permissions.has()to check forManageMessagesorAdministratorpermissions.- Error handling for invalid input (e.g., non-numeric or out-of-range values) and deletion failures.
- Ephemeral replies for slash commands to ensure privacy.
Banner
The `banner` command allows users to display a user's banner in a Discord server. It can be triggered using the prefixes `P`, `p`, or the slash command `/`.
Icon
The `icon` command allows users to display the server's icon in a Discord server. It can be triggered using the prefixes `P`, `p`, or the slash command `/`.