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:
parent
f4be18e082
commit
07960fe348
20
README.md
20
README.md
@ -393,21 +393,19 @@ telebot.logger.setLevel(logging.DEBUG) # Outputs debug messages to console.
|
|||||||
## F.A.Q.
|
## F.A.Q.
|
||||||
|
|
||||||
### How can I distinguish a User and a GroupChat in message.chat?
|
### 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
|
```python
|
||||||
def is_user(chat):
|
if message.chat.type == “private”:
|
||||||
return isinstance(chat, types.User)
|
# private chat message
|
||||||
|
|
||||||
print is_user(message.chat) # True or False
|
if message.chat.type == “group”:
|
||||||
```
|
# group chat message
|
||||||
- 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
|
if message.chat.type == “channel”:
|
||||||
def is_user(chat):
|
# channel message
|
||||||
return chat.id > 0
|
|
||||||
|
|
||||||
print is_user(message.chat) # True or False
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## The Telegram Chat Group
|
## The Telegram Chat Group
|
||||||
|
Loading…
Reference in New Issue
Block a user