restrictChatMember method
Future<bool>
restrictChatMember(
- int userId,
- ChatPermissions permissions, {
- DateTime? untilDate,
- bool? useIndependentChatPermissions,
Restricts a user in the current chat.
This method is a shortcut for RawAPI.restrictChatMember using the current chat. Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights.
Parameters:
userId: Unique identifier of the target userpermissions: A ChatPermissions object for new user permissionsuntilDate: Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted foreveruseIndependentChatPermissions: Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
Returns True on success.
Example:
// Restrict user from sending messages
final permissions = ChatPermissions(canSendMessages: false);
await ctx.restrictChatMember(123456789, permissions);
// Restrict user temporarily
await ctx.restrictChatMember(
123456789,
permissions,
untilDate: DateTime.now().add(Duration(hours: 1)),
);
// Restrict with independent permissions
await ctx.restrictChatMember(
123456789,
permissions,
useIndependentChatPermissions: true,
);
Implementation
Future<bool> restrictChatMember(
int userId,
ChatPermissions permissions, {
DateTime? untilDate,
bool? useIndependentChatPermissions,
}) async {
final chatId = _getChatId();
_verifyInfo([chatId], APIMethod.restrictChatMember);
return api.restrictChatMember(
chatId!,
userId,
permissions,
untilDate: untilDate,
useIndependentChatPermissions: useIndependentChatPermissions,
);
}