> For the complete documentation index, see [llms.txt](https://degreetpro.gitbook.io/nestgram/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://degreetpro.gitbook.io/nestgram/api-reference/ban-unban-user-or-chat.md).

# 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 %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://degreetpro.gitbook.io/nestgram/api-reference/ban-unban-user-or-chat.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
