muteChatMember method
Mutes a user in the current chat by restricting their ability to send messages.
This is a convenience method that creates ChatPermissions with
canSendMessages set to false and calls restrictChatMember.
Parameters:
userId: Unique identifier of the target useruntilDate: Date when the mute will be liftedallowMedia: Whether to allow sending media (photos, videos, etc.)allowOther: Whether to allow other message types (stickers, GIFs, etc.)
Returns True on success.
Example:
// Mute user permanently
await ctx.muteChatMember(123456789);
// Mute user for 1 hour
await ctx.muteChatMember(
123456789,
untilDate: DateTime.now().add(Duration(hours: 1)),
);
// Mute but allow media
await ctx.muteChatMember(123456789, allowMedia: true);
Implementation
Future<bool> muteChatMember(
int userId, {
DateTime? untilDate,
bool allowMedia = false,
bool allowOther = false,
}) async {
final permissions = ChatPermissions(
canSendMessages: false,
canSendAudios: allowMedia,
canSendDocuments: allowMedia,
canSendPhotos: allowMedia,
canSendVideos: allowMedia,
canSendVideoNotes: allowMedia,
canSendVoiceNotes: allowMedia,
canSendPolls: false,
canSendOtherMessages: allowOther,
canAddWebPagePreviews: allowOther,
canChangeInfo: false,
canInviteUsers: false,
canPinMessages: false,
canManageTopics: false,
);
return restrictChatMember(userId, permissions, untilDate: untilDate);
}