Clearer error on send_file(chat, invalid type)

This commit is contained in:
Lonami Exo 2019-02-19 16:41:51 +01:00
parent f540c4e089
commit 6db60627e6
2 changed files with 9 additions and 1 deletions

View File

@ -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,

View File

@ -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).'