0

Telegram client has rich Chat media permissions (Can send stickers, Can send videos, etc). How can I check if stickers, images or videos can be sent in chat using Pyrogram?

IML
  • 181
  • 2
  • 7

1 Answers1

1

To check the chat media permissions using Pyrogram, you can use the get_chat_member method provided by the Pyrogram library.

from pyrogram import Client

# Create a Pyrogram client
api_id = "YOUR_API_ID"
api_hash = "YOUR_API_HASH"

with Client("my_account", api_id, api_hash) as app:
    # Get the chat information
    chat_id = "YOUR_CHAT_ID"
    user_id = "YOUR_USER_ID"
    chat_member = app.get_chat_member(chat_id, user_id)

    # Check chat media permissions
    can_send_stickers = chat_member.can_send_stickers
    can_send_videos = chat_member.can_send_videos

    print("Can send stickers:", can_send_stickers)
    print("Can send videos:", can_send_videos)

    # Send a sticker if allowed
    if can_send_stickers:
        sticker_file_path = "path_to_sticker_file.png"  # Path to the sticker file
        app.send_sticker(chat_id=chat_id, sticker=sticker_file_path)
    else:
        print("Cannot send stickers in this chat.")

    # Send a video if allowed
    if can_send_videos:
        video_file_path = "path_to_video_file.mp4"  # Path to the video file
        app.send_video(chat_id=chat_id, video=video_file_path)
    else:
        print("Cannot send videos in this chat.")

The get_chat_member method retrieves information about a chat member, including their permissions. You can access the specific media permissions using attributes like can_send_stickers, can_send_videos, etc. Use send_sticker and send_video methods to send stickers and video.

  • Thanks for comment, very useful info, but I meant how can I know if stickers, images or videos can be sent in chat? I have member status, this code for admin only (maybe chat settings) – IML May 20 '23 at 03:34
  • To send stickers and videos in Telegram using Pyrogram, you can utilize the `send_sticker` and `send_video` methods provided by the Pyrogram library. – Maneesha Indrachapa May 22 '23 at 07:41
  • Yes I can how can i know are stickers active or not? This creates an extra load, and Telegram also have limits on api calls. – IML May 22 '23 at 07:49