# clean

This command deletes a specified amount of messages from a channel. The command can be optionally limited by criteria, such as deleting only messages from bots, as seen in the [Options](#options) section below.

{% hint style="info" %}
Due to limitations imposed by Discord, only messages sent within the last 14 days can be deleted.
{% endhint %}

## Required permissions

MoonlightBot requires the following permissions to successfully execute this command:

* View Channel
* Send Messages
* Manage Messages
* Read Message History

By default, a user is required to have the following permissions to use this command:

* Manage Messages

For more information on editing permission requirements for specific users/roles, refer to the [permissions tutorial](/docs/get-started/permission-tutorial.md)

## Syntax

```
/clean [amount] [user] [starts-with] [ends-with] [contains] [bots] [system] [preserve-pins] [no-trace]
```

### Options

* `amount`: The amount of messages you want to clean (The default/maximum amount is 100)
* `user`: Delete messages sent by a specified user
* `starts-with`: Delete messages that start with this value
* `ends-with`: Delete messages that end with this value
* `contains`: Delete messages that contain this value
* `bots`: Whether or not to delete messages sent by bots. If this option is left blank, the bot will not differentiate between messages sent by users and bots. If set to false, the bot will not delete bot messages, but if set to true, the bot will only delete bot messages
* `system`: Whether or not to delete system messages. System messages are messages sent by Discord, such as join or pin messages. This uses the same syntax as the `bots` option
* `preserve-pins`: If true, pinned messages will not be deleted
* `no-trace`: If true, the confirmation message will only be visible to you

## Logs

* `CHANNEL_CLEAN`: MoonlightBot will send a message with two things: an HTML file that contains the history of the deleted messages and an embed detailing where messages were cleaned, how many were cleaned, who cleaned them, and the filters applied

![An example of logs sent by the bot after a clean command execution](/files/Y15229lUans4I04Ln6ib)

{% hint style="info" %}
Rather than rendering them like other downloadable files, Discord displays the raw content of HTML files. To download the HTML file, click the download button at the bottom-right of the file display. Double-click the file, and your computer will open a new tab in your browser to display a visualization of the messages deleted.
{% endhint %}

For more information on setting up those logs, refer to the [log setup tutorial](/docs/readme.md#logging)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://moonlightbot.gitbook.io/docs/moderation-commands/clean.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
