1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Update new type chat document.

This commit is contained in:
FrankWang 2015-10-12 23:00:25 +08:00
parent f4be18e082
commit 07960fe348

View File

@ -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