From 07960fe348c4150936a772ad6069920456d409b5 Mon Sep 17 00:00:00 2001 From: FrankWang Date: Mon, 12 Oct 2015 23:00:25 +0800 Subject: [PATCH] Update new type chat document. --- README.md | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e46ce0a..edf44f8 100644 --- a/README.md +++ b/README.md @@ -393,21 +393,19 @@ telebot.logger.setLevel(logging.DEBUG) # Outputs debug messages to console. ## F.A.Q. ### How can I distinguish a User and a GroupChat in message.chat? -There are two ways to do this: +Telegram Bot API support new type Chat for message.chat. - - Checking the instance of message.chat with `isinstance`: +- Check the ```type``` attribute in ```Chat``` object: ```python -def is_user(chat): - return isinstance(chat, types.User) +if message.chat.type == “private”: + # private chat message -print is_user(message.chat) # True or False -``` - - Checking whether the chat id is negative or positive. If the chat id is negative, the chat is a GroupChat, if it is positive, it is a User. Example: -```python -def is_user(chat): - return chat.id > 0 +if message.chat.type == “group”: + # group chat message + +if message.chat.type == “channel”: + # channel message -print is_user(message.chat) # True or False ``` ## The Telegram Chat Group