D
D
Dmitry2021-12-09 13:37:00
Python
Dmitry, 2021-12-09 13:37:00

How to make verification through sender_chat?

Tell me how to check if the sender of the message is a group administrator. I am using the PyTelegramBotApi library.

I found in the documentation how now to make a verification code out of all this.

status Member's chat status, always “administrator”
user User information

get_chat_member( chat_id , user_id , timeout = None , api_kwargs = None )
Use this method to get information about a chat member.
Returns a ChatMember object if successful.
chat_id The unique ID for the target chat, or the username of the target supergroup or channel (in @channelusername format)
user_id The unique ID of the target

ChatMember user

This object contains information about one chat member:
I figured I only need these 2.
ChatMemberAdministrator
ChatMemberMember

ChatMemberAdministrator
Represents a chat member with some additional privileges.

chat (telegram.Chat) - the conversation the message belongs to.

message_id (int) - The unique ID of the message within this chat.

sender_chat - The sender of a message sent on behalf of a chat. The channel itself is for channel messages. The supergroup itself for messages from anonymous group admins. Associated channel for messages automatically forwarded to the discussion group.

forward_from_chat
Optional. For messages forwarded through channels or from anonymous admins, information about the sender's original chat.

forward_sender_name (str, optional) - the name of the sender of messages forwarded from users who do not allow a link to their account to be added in forwarded messages.

forward_from
Optional. The sender of the original message.

from_user (telegram.User, optional) - Sender, empty for messages sent to channels.

getChatAdministrators
$params = [ 'chat_id' => '', ];
getChatMember()
$params = [ 'chat_id' => '', 'user_id' => '', ];

sendMessage() публичный метод
$params = [ 'chat_id' => '', 'text' => '', 'parse_mode' => '', 'disable_web_page_preview' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];

def get_chat_member(self, chat_id, user_id):


I once asked a question, they sent me this code, and it’s useless, because, in my code, it’s forbidden to post links, but for administrators too, but according to the idea, everything should be allowed for administrators.
See who sent the message, and if the sender is a supergroup, then do nothing.

if message.sender_chat and message.sender_chat == "supergroup":
    return


All code
import telebot
import time 
from telebot import types
from telebot import custom_filters
from telegram.ext import Filters
from telegram.error import BadRequest
from telebot.apihelper import ApiTelegramException

bot = telebot.TeleBot("moy_token")

@bot.message_handler(func=lambda message: message.entities is not None and message.chat.id)
def delete_links(message):
    for entity in message.entities:
        if entity.type in ["url", "text_link"]:
         if message.sender_chat and message.sender_chat == "supergroup":
          return
         bot.delete_message(message.chat.id, message.message_id)
        else:
            return



if __name__ == "__main__":
#RUN
 bot.polling(none_stop=True)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question