telegram.game module¶
This module contains an object that represents a Telegram Game.
-
class
telegram.game.Game(title, description, photo, text='', text_entities=None, animation=None, **kwargs)¶ Bases:
telegram.base.TelegramObjectThis object represents a Telegram Game.
-
title¶ str – Title of the game.
-
description¶ str – Description of the game.
-
photo¶ list[
telegram.PhotoSize] – List of photos that will be displayed in the game message in chats.
Keyword Arguments: - text (Optional[str]) – 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 setGameScore, or manually edited using editMessageText. 0-4096 characters.
- text_entities (Optional[list[
telegram.MessageEntity]]) – Special entities that appear in text, such as usernames, URLs, bot commands, etc. - animation (Optional[
telegram.Animation]) – Animation that will be displayed in the game message in chats. Upload via BotFather.
-
static
de_json(data, bot)¶ Parameters: - data (dict) –
- bot (telegram.Bot) –
Returns: Return type:
-
parse_text_entities(types=None)¶ Returns a
dictthat mapstelegram.MessageEntitytostr. It contains entities from this message filtered by theirtypeattribute 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
entitiesattribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. Seeget_entity_textfor more info.Parameters: types (Optional[list]) – List of MessageEntitytypes as strings. If thetypeattribute of an entity is contained in this list, it will be returned. Defaults to a list of all types. All types can be found as constants intelegram.MessageEntity.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)¶ 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.textwith 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: str
-
to_dict()¶ Returns: Return type: dict
-