From 6db60627e6343568c008d6bd48ee07bdb6d97e1a Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 19 Feb 2019 16:41:51 +0100 Subject: [PATCH] Clearer error on send_file(chat, invalid type) --- telethon/client/uploads.py | 8 ++++++++ telethon_examples/assistant.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/telethon/client/uploads.py b/telethon/client/uploads.py index c1c43f60..b7518ccb 100644 --- a/telethon/client/uploads.py +++ b/telethon/client/uploads.py @@ -184,6 +184,10 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods): The `telethon.tl.custom.message.Message` (or messages) containing the sent file, or messages if a list of them was passed. """ + # i.e. ``None`` was used + if not file: + raise TypeError('Cannot use {!r} as file'.format(file)) + if not caption: caption = '' @@ -243,6 +247,10 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods): supports_streaming=supports_streaming ) + # e.g. invalid cast from :tl:`MessageMediaWebPage` + if not media: + raise TypeError('Cannot use {!r} as file'.format(file)) + markup = self.build_reply_markup(buttons) request = functions.messages.SendMediaRequest( entity, media, reply_to_msg_id=reply_to, message=caption, diff --git a/telethon_examples/assistant.py b/telethon_examples/assistant.py index 1eb00251..586b55a7 100644 --- a/telethon_examples/assistant.py +++ b/telethon_examples/assistant.py @@ -313,7 +313,7 @@ async def handler(event): text = 'Available commands:\n' for callback, handler in bot.list_event_handlers(): if isinstance(handler, events.NewMessage) and callback.__doc__: - text += f'\n{callback.__doc__}' + text += f'\n{callback.__doc__.strip()}' text += '\n\nYou can suggest new commands [here](https://docs.google.com/'\ 'spreadsheets/d/12yWwixUu_vB426_toLBAiajXxYKvR2J1DD6yZtQz9l4/edit).'