當前位置: 首頁>>代碼示例>>Python>>正文


Python error.TelegramError方法代碼示例

本文整理匯總了Python中telegram.error.TelegramError方法的典型用法代碼示例。如果您正苦於以下問題:Python error.TelegramError方法的具體用法?Python error.TelegramError怎麽用?Python error.TelegramError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在telegram.error的用法示例。


在下文中一共展示了error.TelegramError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_me

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def get_me(self, timeout=None, **kwargs):
        """A simple method for testing your bot's auth token. Requires no parameters.

        Args:
            timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
                the read timeout from the server (instead of the one specified during creation of
                the connection pool).

        Returns:
            :class:`telegram.User`: A :class:`telegram.User` instance representing that bot if the
            credentials are valid, :obj:`None` otherwise.

        Raises:
            :class:`telegram.TelegramError`

        """
        url = '{0}/getMe'.format(self.base_url)

        result = self._request.get(url, timeout=timeout)

        self.bot = User.de_json(result, self)

        return self.bot 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:25,代碼來源:bot.py

示例2: delete_webhook

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def delete_webhook(self, timeout=None, **kwargs):
        """
        Use this method to remove webhook integration if you decide to switch back to
        getUpdates. Requires no parameters.

        Args:
            timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
                the read timeout from the server (instead of the one specified during creation of
                the connection pool).
            **kwargs (:obj:`dict`): Arbitrary keyword arguments.

        Returns:
            :obj:`bool` On success, ``True`` is returned.

        Raises:
            :class:`telegram.TelegramError`

        """
        url = '{0}/deleteWebhook'.format(self.base_url)

        data = kwargs

        result = self._request.post(url, data, timeout=timeout)

        return result 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:27,代碼來源:bot.py

示例3: delete_sticker_from_set

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def delete_sticker_from_set(self, sticker, timeout=None, **kwargs):
        """Use this method to delete a sticker from a set created by the bot.

        Args:
            sticker (:obj:`str`): File identifier of the sticker.
            timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
                the read timeout from the server (instead of the one specified during
                creation of the connection pool).
            **kwargs (:obj:`dict`): Arbitrary keyword arguments.

        Returns:
            :obj:`bool`: On success, ``True`` is returned.

        Raises:
            :class:`telegram.TelegramError`

        """
        url = '{0}/deleteStickerFromSet'.format(self.base_url)

        data = {'sticker': sticker}
        data.update(kwargs)

        result = self._request.post(url, data, timeout=timeout)

        return result 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:27,代碼來源:bot.py

示例4: file_id_query_received

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def file_id_query_received(update: Update, context: CallbackContext):
    # get query
    query = update.inline_query
    user_id = query.from_user.id
    results = None

    try:
        file = bot.get_file(query.query)

        _id = uuid.uuid4()
        title = get_message(user_id, "your_sticker")
        desc = get_message(user_id, "forward_desc")
        caption = "@EzStickerBot"
        results = [InlineQueryResultCachedDocument(_id, title, file.file_id, description=desc, caption=caption)]

        query.answer(results=results, cache_time=5, is_personal=True)
    # if file_id wasn't found show share option
    except TelegramError:
        share_query_received(update, context) 
開發者ID:fxuls,項目名稱:ez-sticker-bot,代碼行數:21,代碼來源:ezstickerbot.py

示例5: error_callback

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def error_callback(bot, update, error):
    try:
        raise error
    except Unauthorized:
        print("no nono1")
        print(error)
        # remove update.message.chat_id from conversation list
    except BadRequest:
        print("no nono2")
        print("BadRequest caught")
        print(error)

        # handle malformed requests - read more below!
    except TimedOut:
        print("no nono3")
        # handle slow connection problems
    except NetworkError:
        print("no nono4")
        # handle other connection problems
    except ChatMigrated as err:
        print("no nono5")
        print(err)
        # the chat_id of a group has changed, use e.new_chat_id instead
    except TelegramError:
        print(error)
        # handle all other telegram related errors 
開發者ID:skittles9823,項目名稱:SkittBot,代碼行數:28,代碼來源:__main__.py

示例6: send_to_list

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def send_to_list(bot: Bot, send_to: list, message: str, markdown=False, html=False) -> None:
    if html and markdown:
        raise Exception("Can only send with either markdown or HTML!")
    for user_id in set(send_to):
        try:
            if markdown:
                bot.send_message(user_id, message, parse_mode=ParseMode.MARKDOWN)
            elif html:
                bot.send_message(user_id, message, parse_mode=ParseMode.HTML)
            else:
                bot.send_message(user_id, message)
        except TelegramError:
            pass  # ignore users who fail 
開發者ID:skittles9823,項目名稱:SkittBot,代碼行數:15,代碼來源:misc.py

示例7: finish

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def finish(self):
        # set last update
        self.channel.last_update = datetime.date.today()
        self._save_channel()

        new_bots = Bot.select_new_bots()
        if not self.silent and len(new_bots) > 0:
            self.notify_admin("Sending notifications to subscribers...")
            subscribers = Notifications.select().where(Notifications.enabled == True)
            notification_count = 0
            for sub in subscribers:
                try:
                    util.send_md_message(self.bot, sub.chat_id,
                                         messages.BOTLIST_UPDATE_NOTIFICATION.format(
                                             n_bots=len(new_bots),
                                             new_bots=Bot.get_new_bots_markdown()))
                    notification_count += 1
                    sub.last_notification = datetime.date.today()
                    sub.save()
                except TelegramError:
                    pass
            self.sent['notifications'] = "Notifications sent to {} users.".format(
                notification_count)

        changes_made = len(self.sent) > 1 or len(self.sent['category']) > 0
        if changes_made:
            text = util.success('{}{}'.format('BotList updated successfully:\n\n',
                                              mdformat.results_list(self.sent)))
        else:
            text = mdformat.none_action("No changes were necessary.")

        log.info(self.sent)
        self.bot.formatter.send_or_edit(self.chat_id, text, to_edit=self.message_id) 
開發者ID:JosXa,項目名稱:BotListBot,代碼行數:35,代碼來源:botlist.py

示例8: check_requirements

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def check_requirements(self):
        try:
            self.bot.get_me()
            self.bot.send_message(chat_id=self.chat_id, text="Kimsufi Crawler started")
        except TelegramError as te:
            _logger.error("Telegram validation failed: {error}".format(error=te.message))
            raise 
開發者ID:MA3STR0,項目名稱:kimsufi-crawler,代碼行數:9,代碼來源:telegram_notifier.py

示例9: notify

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def notify(self, title, text, url=None):
        try:
            self.bot.send_message(chat_id=self.chat_id, text=text)
        except TelegramError as te:
            _logger.error("Something went wrong sending the message to Telegram:")
            _logger.error(te) 
開發者ID:MA3STR0,項目名稱:kimsufi-crawler,代碼行數:8,代碼來源:telegram_notifier.py

示例10: delete_message

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def delete_message(self, chat_id, message_id, timeout=None, **kwargs):
        """
        Use this method to delete a message. A message can only be deleted if it was sent less
        than 48 hours ago. Any such recently sent outgoing message may be deleted. Additionally,
        if the bot is an administrator in a group chat, it can delete any message. If the bot is
        an administrator in a supergroup, it can delete messages from any other user and service
        messages about people joining or leaving the group (other types of service messages may
        only be removed by the group creator). In channels, bots can only remove their own
        messages.

        Args:
            chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
                of the target channel (in the format @channelusername).
            message_id (:obj:`int`): Identifier of the message to delete.
            timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
            the read timeout
                from the server (instead of the one specified during creation of the connection
                pool).
            **kwargs (:obj:`dict`): Arbitrary keyword arguments.

        Returns:
            :obj:`bool`: On success, ``True`` is returned.

        Raises:
            :class:`telegram.TelegramError`

        """
        url = '{0}/deleteMessage'.format(self.base_url)

        data = {'chat_id': chat_id, 'message_id': message_id}

        result = self._request.post(url, data, timeout=timeout)

        return result 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:36,代碼來源:bot.py

示例11: send_game

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def send_game(self,
                  chat_id,
                  game_short_name,
                  disable_notification=False,
                  reply_to_message_id=None,
                  reply_markup=None,
                  timeout=None,
                  **kwargs):
        """Use this method to send a game.

        Args:
            chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
                of the target channel (in the format @channelusername).
            game_short_name (:obj:`str`): Short name of the game, serves as the unique identifier
                for the game. Set up your games via Botfather.
            disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
                receive a notification with no sound.
            reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
                original message.
            reply_markup (:class:`telegram.ReplyMarkup`, optional): Additional interface options. A
                JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
                to remove reply keyboard or to force a reply from the user.
            timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
                the read timeout from the server (instead of the one specified during creation of
                the connection pool).
            **kwargs (:obj:`dict`): Arbitrary keyword arguments.

        Returns:
            :class:`telegram.Message`: On success, the sent Message is returned.

        Raises:
            :class:`telegram.TelegramError`

        """
        url = '{0}/sendGame'.format(self.base_url)

        data = {'chat_id': chat_id, 'game_short_name': game_short_name}

        return url, data 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:41,代碼來源:bot.py

示例12: get_user_profile_photos

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def get_user_profile_photos(self, user_id, offset=None, limit=100, timeout=None, **kwargs):
        """Use this method to get a list of profile pictures for a user.

        Args:
            user_id (:obj:`int`): Unique identifier of the target user.
            offset (:obj:`int`, optional): Sequential number of the first photo to be returned.
                By default, all photos are returned.
            limit (:obj:`int`, optional): Limits the number of photos to be retrieved. Values
                between 1-100 are accepted. Defaults to 100.
            timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
                the read timeout from the server (instead of the one specified during creation of
                the connection pool).
            **kwargs (:obj:`dict`): Arbitrary keyword arguments.

        Returns:
            :class:`telegram.UserProfilePhotos`

        Raises:
            :class:`telegram.TelegramError`

        """
        url = '{0}/getUserProfilePhotos'.format(self.base_url)

        data = {'user_id': user_id}

        if offset is not None:
            data['offset'] = offset
        if limit:
            data['limit'] = limit
        data.update(kwargs)

        result = self._request.post(url, data, timeout=timeout)

        return UserProfilePhotos.de_json(result, self) 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:36,代碼來源:bot.py

示例13: get_file

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def get_file(self, file_id, timeout=None, **kwargs):
        """
        Use this method to get basic info about a file and prepare it for downloading. For the
        moment, bots can download files of up to 20MB in size. The file can then be downloaded
        with :attr:`telegram.File.download`. It is guaranteed that the link will be
        valid for at least 1 hour. When the link expires, a new one can be requested by
        calling getFile again.

        Args:
            file_id (:obj:`str`): File identifier to get info about.
            timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
                the read timeout from the server (instead of the one specified during creation of
                the connection pool).
            **kwargs (:obj:`dict`): Arbitrary keyword arguments.

        Returns:
            :class:`telegram.File`

        Raises:
            :class:`telegram.TelegramError`

        """
        url = '{0}/getFile'.format(self.base_url)

        data = {'file_id': file_id}
        data.update(kwargs)

        result = self._request.post(url, data, timeout=timeout)

        if result.get('file_path'):
            result['file_path'] = '%s/%s' % (self.base_file_url, result['file_path'])

        return File.de_json(result, self) 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:35,代碼來源:bot.py

示例14: unban_chat_member

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def unban_chat_member(self, chat_id, user_id, timeout=None, **kwargs):
        """Use this method to unban a previously kicked user in a supergroup.

        The user will not return to the group automatically, but will be able to join via link,
        etc. The bot must be an administrator in the group for this to work.

        Args:
            chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
                of the target channel (in the format @channelusername).
            user_id (:obj:`int`): Unique identifier of the target user.
            timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
                the read timeout from the server (instead of the one specified during creation of
                the connection pool).
            **kwargs (:obj:`dict`): Arbitrary keyword arguments.

        Returns:
            :obj:`bool` On success, ``True`` is returned.

        Raises:
            :class:`telegram.TelegramError`

        """
        url = '{0}/unbanChatMember'.format(self.base_url)

        data = {'chat_id': chat_id, 'user_id': user_id}
        data.update(kwargs)

        result = self._request.post(url, data, timeout=timeout)

        return result 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:32,代碼來源:bot.py

示例15: leave_chat

# 需要導入模塊: from telegram import error [as 別名]
# 或者: from telegram.error import TelegramError [as 別名]
def leave_chat(self, chat_id, timeout=None, **kwargs):
        """Use this method for your bot to leave a group, supergroup or channel.

        Args:
            chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
                of the target`channel (in the format @channelusername).
            timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
                the read timeout from the server (instead of the one specified during creation of
                the connection pool).
            **kwargs (:obj:`dict`): Arbitrary keyword arguments.

        Returns:
            :obj:`bool` On success, ``True`` is returned.

        Raises:
            :class:`telegram.TelegramError`

        """
        url = '{0}/leaveChat'.format(self.base_url)

        data = {'chat_id': chat_id}
        data.update(kwargs)

        result = self._request.post(url, data, timeout=timeout)

        return result 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:28,代碼來源:bot.py


注:本文中的telegram.error.TelegramError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。