Clear (English)

The Clear command allows a user to clear a specific chat for a certain amount of messages. By default, the user must have a power of 1 (Moderator) to use this command.

## Syntax

Like all commands, the Clear command needs to start with the server's command prefix. Then followed by the word "clear" or "clean". There are many arguments for this command, primarily mentioning a number of messages. You can also mention users to clear specific user's messages.

**Other Arguments:**

* **Range:** This is rather complicated to grasp initially, you select a range by mentioning numbers in this format 4;10 which means delete message 4 to 10 from the last message. For further explanation/demonstration watch the tutorial video.
* **Nopinned:** No pinned messages will be deleted from the X amount of messages you indicated. This means if there are 100 messages you selected and one is pinned only 99 will be deleted. Since it is a keyword just adding it anywhere in the command will work.
* **Onlybot:** As it states, it will delete ONLY the bot account messages, which includes other bots and not just the Phoenix Bot. Since it is a keyword just adding it anywhere in the command will work.
* **Onlyuser:** As it states, it will delete ONLY the user messages. Since it is a keyword just adding it anywhere in the command will work.
* **Noembed:** As it states, it will delete ONLY the user messages. Since it is a keyword just adding it anywhere in the command will work.

All these can be arguments can be combined, however, take note that it will first receive the messages you specified and then only start filtering, the number you specified did not mean the number of messages deleted. More the number of *possible* messages that could be deleted.

Examples of the above which were talked about:

```
!clear 100          -> Clears the earliest 100 messages from the channel.

!clean 100 @user    -> Filters the earliest 100 messages and deletes only the ones sent by the user mentioned.

!clear 100 nopinned -> Filters the earliest 100 messages and deletes only the ones that are not pinned.

!clear 100 onlybot  -> Filters the earliest 100 messages and deletes only the ones that are from bots

!clear 100 onlyuser -> Filters the earliest 100 messages and deletes only the ones that are from users

!clear 100 noembed  -> Filters the earliest 100 messages and deletes only the ones that are not embeds.

!clear 10;40        -> Gets the earliest 40 messages and deletes them until it reaches the 10 earliest messages where it will delete the message and stop.

```

## How does it work?

The bot will scan through your message looking for numbers and combining them. That is to say, if the command has two number which are separated by an unknown separator, anything other than '**;**', then it will assume you mean a single number so you can do '!clear 10 0' and it will consider that to be 100. *This can also be a problem if you still are using '**-**' as a separator since it will read it as a single number\**. If no number is found then an error message will be sent.

It then stores the number received and gets all the messages before your message up to the number you sent.

Then it will scan through your message also to get any arguments, as listed above, be mindful that the bot is unable to tell if you accidentally miss-typed an argument and didn't do it fully like if you type 'onlybo' instead of 'onlybot' it will consider there to be no argument.

It will filter the X amount (The number you sent) of messages you indicated earlier and delete them. This could mean that no messages get deleted or messages do get deleted depending on your range of messages you chose and the arguments you selected. After they get deleted the bot will store the messages in a text file in case of accidental deletion of key information. It will attempt to preserve as many details about the content of the message.

The bot will then send a confirmation message saying how many messages were **actually** deleted and then the message itself will be removed after 15 seconds.

*\*Explained further under Errors and how to deal with them...*

```
1. Get a number from the message (If no message found send error)

```

```
2. Get all the messages before your message up to the number indicated.

```

```
3. Get arguments and filter the messages received earlier.

```

```
4. Delete the messages and save the messages deleted to a text file.

```

```
5. Send confirmation message of the amount of messages deleted.

```

## Errors and how to deal with them...

If there is an error at any point in the command it will give you a brief description of the error which is sometimes ineffective in explaining it. Here are some common errors you will face:

* **No messages deleted:** This is a warning rather than an error as there was nothing actually "wrong" more so it couldn't delete the messages because no messages matched the filters you chose OR the messages that you tried to delete were 2 weeks and above old. *As of writing this page !clear all is not a function.*
* **Too many messages are deleted:** This isn't fully checked by the bot, and as such, there is a command to recover messages in a text file. If the command you entered deleted more messages than it should of you most likely used the wrong separator. In the example '**!clear 10-30'** the bot will read it as 1030 messages. This is because '-' is not recognised as a separator. This is an unfortunate by-product of trying to make the command more robust. The command does not rely on the position of the numbers to get the number of messages received. As long as they are read from right to left it will work. Should this happen in your Discord server, as previously stated, there is a command to receive the most recent deletion called restore.

* **Other error:** If another error occurs then join the support Discord.