Nestgram
  • ⭐About Nestgram
  • 📄Guide
  • 📰News
  • đŸ”ŧHandling updates
    • Handling commands
    • Handling text messages
    • Handling other updates
    • Entities: url, email and other
    • Other arguments in handler
    • Handling media files and download it
  • đŸĒļNestgram Features
    • Services
    • Middlewares and Params
    • Sending messages correctly
    • Answer class
    • Scopes
    • States
    • Views
  • đŸ’ŦMessages
    • Sending a photo, video and other media
    • Sending a media group
    • Send location (live) or venue
    • Send contact
    • Send poll
    • Send dice
    • Edit/delete messages
    • Copy or Forward a message
  • âŒ¨ī¸Keyboards
    • Keyboard types, building keyboard
    • Handle underTheMessage keyboard button click by Alert or Toast
    • Keyboard layouts
  • âš™ī¸Config
    • CLI
    • Webhooks and run config
    • Api class
    • Modules
      • Mongo module
    • Controller Helper class
  • 🤖API Reference
    • Set chat action
    • Save user profile photo
    • Ban, unban user or chat
    • Restrict or Promote user
    • Set chat permissions
    • Set chat admin custom title
    • Chat invite links
    • Join requests
    • Update chat info, photo, title, description and more
    • Pin or unpin messages
    • Get chat info, leave chat
    • Check user subscription
    • Chat sticker set
    • My commands
    • My default admin rights
    • Menu button
Powered by GitBook
On this page
  1. API Reference

Ban, unban user or chat

You can ban and unban chat member

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

Using these methods, you can also ban users who write via chats

app.controller.ts
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();
  }
}

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

Argument
Description
Required
1

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

Optional

2

Revoke messages. Pass true to delete all messages from the chat for the user that is being removed

Optional

3

User ID you want to ban

Optional. Current user id by default

.unban Answer method take arguments:

Argument
Description
Required
1

Only if banned. Do nothing if user is unbanned

Optional

2

User id you want to unban

Optional. Current user id by default

If you want to know what arguments Api methods takes, see IDE hints

PreviousSave user profile photoNextRestrict or Promote user

Last updated 2 years ago

🤖