Answer the question
In order to leave comments, you need to log in
How to use "getChatMember"?
Please tell me how can I check if the chat user is an administrator, but I don't know how to use this, on this PyTelegramBotApi though I read the documentation.
status - The status of the participant in the chat. May be ADMINISTRATOR, CREATOR, KICKED, LEFT, MEMBER, or RESTRICTED.
get_chat_member( chat_id , user_id , timeout = None , api_kwargs = None )
Use this method to get information about a chat member.
chat_id ( int| str) - Unique ID of the target chat or username of the target supergroup or channel (in @channelusername format).
user_id ( int) - The unique ID of the target user.
And now how to make a check out of this, so that the code checks the admin user or not, if for example the user, then for posting a link in the chat blocking, and the admin can post any link.
All code.
import telebot
import time
from telebot import types
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
If you already have an admins ID, then check the required handler
. I did this myself
async def cm_start(message: types.Message):
if message.from_user.id == ID:
getChatAdministrators
method
Use this method to get a list of chat administrators. If successful, returns an array of ChatMember objects that contains information about all chat admins, except for other bots. If the chat is a group or supergroup and no admins have been assigned, only the creator will be returned.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question