# Ban, unban user or chat

To ban the user, use `.ban` **answer/api method** or **Ban class-method**. To unban the user, use `.unban` **answer/api method**. This is an example where we ban a user if they type "\*\*\*\*" in the chat and unban after 5 seconds

{% hint style="info" %}
Using these methods, you can also ban users who write via chats
{% endhint %}

{% code title="app.controller.ts" %}

```typescript
import { Controller, GetAnswer, Answer, OnText, Ban } from 'nestgram';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @OnText('****')
  async banHello(@GetAnswer() answer: Answer) {
    setTimeout(() => answer.unban(), 5000);
    return new Ban();
  }
}
```

{% endcode %}

#### Ban class-method or .ban Answer method take arguments:

<table><thead><tr><th width="150" data-type="number">Argument</th><th width="398.9839381320643">Description</th><th>Required</th></tr></thead><tbody><tr><td>1</td><td>Until ban date (unix date). If a user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only</td><td>Optional</td></tr><tr><td>2</td><td>Revoke messages. Pass <code>true</code> to delete all messages from the chat for the user that is being removed</td><td>Optional</td></tr><tr><td>3</td><td>User ID you want to ban</td><td>Optional. Current user id by default</td></tr></tbody></table>

#### .unban Answer method take arguments:

<table><thead><tr><th width="150" data-type="number">Argument</th><th width="358.66716988562706">Description</th><th>Required</th></tr></thead><tbody><tr><td>1</td><td>Only if banned. Do nothing if user is unbanned</td><td>Optional</td></tr><tr><td>2</td><td>User id you want to unban</td><td>Optional. Current user id by default</td></tr></tbody></table>

{% hint style="info" %}
If you want to know what arguments Api methods takes, see IDE hints
{% endhint %}
