Game¶
- class telegram.Game(title, description, photo, text=None, text_entities=None, animation=None, *, api_kwargs=None)[source]¶
Bases:
telegram.TelegramObject
This object represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers.
Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their
title
,description
andphoto
are equal.Available In
- Parameters:
description (
str
) – Description of the game.photo (Sequence[
telegram.PhotoSize
]) –Photo that will be displayed in the game message in chats.
Changed in version 20.0: Accepts any
collections.abc.Sequence
as input instead of just a list. The input is converted to a tuple.text (
str
, optional) – Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot callstelegram.Bot.set_game_score()
, or manually edited usingtelegram.Bot.edit_message_text()
. 0-4096
characters.text_entities (Sequence[
telegram.MessageEntity
], optional) –Special entities that appear in text, such as usernames, URLs, bot commands, etc.
Changed in version 20.0: Accepts any
collections.abc.Sequence
as input instead of just a list. The input is converted to a tuple.animation (
telegram.Animation
, optional) –Animation that will be displayed in the game message in chats. Upload via BotFather.
- photo[source]¶
Photo that will be displayed in the game message in chats.
Changed in version 20.0: This attribute is now an immutable tuple.
- Type:
tuple[
telegram.PhotoSize
]
- text[source]¶
Optional. Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls
telegram.Bot.set_game_score()
, or manually edited usingtelegram.Bot.edit_message_text()
. 0-4096
characters.- Type:
- text_entities[source]¶
Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. This tuple is empty if the message does not contain text entities.
Changed in version 20.0: This attribute is now an immutable tuple.
- Type:
tuple[
telegram.MessageEntity
]
- animation[source]¶
Optional. Animation that will be displayed in the game message in chats. Upload via BotFather.
- Type:
- parse_text_entities(types=None)[source]¶
Returns a
dict
that mapstelegram.MessageEntity
tostr
. It contains entities from this message filtered by theirtype
attribute as the key, and the text that each entity belongs to as the value of thedict
.Note
This method should always be used instead of the
text_entities
attribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. Seeparse_text_entity
for more info.- Parameters:
types (list[
str
], optional) – List oftelegram.MessageEntity
types as strings. If thetype
attribute of an entity is contained in this list, it will be returned. Defaults totelegram.MessageEntity.ALL_TYPES
.- Returns:
A dictionary of entities mapped to the text that belongs to them, calculated based on UTF-16 codepoints.
- Return type:
dict[
telegram.MessageEntity
,str
]
- parse_text_entity(entity)[source]¶
Returns the text from a given
telegram.MessageEntity
.Note
This method is present because Telegram calculates the offset and length in UTF-16 codepoint pairs, which some versions of Python don’t handle automatically. (That is, you can’t just slice
Message.text
with the offset and length.)- Parameters:
entity (
telegram.MessageEntity
) – The entity to extract the text from. It must be an entity that belongs to this message.- Returns:
The text of the given entity.
- Return type:
- Raises:
RuntimeError – If this game has no text.