banChatMember method

Future<bool> banChatMember(
  1. int userId, {
  2. DateTime? untilDate,
  3. bool? revokeMessages,
})

Bans a user from the current chat.

This method is a shortcut for RawAPI.banChatMember using the current chat. Use this method to ban a user from a group, supergroup or channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first.

Parameters:

  • userId: Unique identifier of the target user
  • untilDate: Date when the user will be unbanned, unix time. If 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.
  • revokeMessages: Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels.

Returns True on success.

Example:

// Ban user permanently
await ctx.banChatMember(123456789);

// Ban user for 1 day
await ctx.banChatMember(
  123456789,
  untilDate: DateTime.now().add(Duration(days: 1)),
);

// Ban user and delete their messages
await ctx.banChatMember(123456789, revokeMessages: true);

Implementation

Future<bool> banChatMember(
  int userId, {
  DateTime? untilDate,
  bool? revokeMessages,
}) async {
  final chatId = _getChatId();
  _verifyInfo([chatId], APIMethod.banChatMember);

  return api.banChatMember(
    chatId!,
    userId,
    untilDate: untilDate,
    revokeMessages: revokeMessages,
  );
}