import telegram
bot = telegram.Bot(token="xxxxxxxxxxxxxxxxxxxxxxxxxxx")
print(bot.get_me())
A json object should be returned with bot details.
When I run the file, it give me the error below.
AttributeError: module 'telegram' has no attribute 'Bot'
I came across a similar closed issue while researching my problem. I do not have a telegram.py file in my project directory. My script is called test.py. I am running Python 3.6.2.
When I run
import telegram
dir(telegram)
I get below output:
['Animation', 'Audio', 'Bot', 'CallbackGame', 'CallbackQuery', 'Chat', 'ChatAction', 'ChatMember
', 'ChatPhoto', 'ChosenInlineResult', 'Contact', 'Document', 'File', 'ForceReply', 'Game', 'Game
HighScore', 'InlineKeyboardButton', 'InlineKeyboardMarkup', 'InlineQuery', 'InlineQueryResult',
'InlineQueryResultArticle', 'InlineQueryResultAudio', 'InlineQueryResultCachedAudio', 'InlineQue
ryResultCachedDocument', 'InlineQueryResultCachedGif', 'InlineQueryResultCachedMpeg4Gif', 'Inlin
eQueryResultCachedPhoto', 'InlineQueryResultCachedSticker', 'InlineQueryResultCachedVideo', 'Inl
ineQueryResultCachedVoice', 'InlineQueryResultContact', 'InlineQueryResultDocument', 'InlineQuer
yResultGame', 'InlineQueryResultGif', 'InlineQueryResultLocation', 'InlineQueryResultMpeg4Gif',
'InlineQueryResultPhoto', 'InlineQueryResultVenue', 'InlineQueryResultVideo', 'InlineQueryResult
Voice', 'InputContactMessageContent', 'InputFile', 'InputLocationMessageContent', 'InputMessageC
ontent', 'InputTextMessageContent', 'InputVenueMessageContent', 'Invoice', 'KeyboardButton', 'La
beledPrice', 'Location', 'MAX_CAPTION_LENGTH', 'MAX_FILESIZE_DOWNLOAD', 'MAX_FILESIZE_UPLOAD', '
MAX_MESSAGES_PER_MINUTE_PER_GROUP', 'MAX_MESSAGES_PER_SECOND', 'MAX_MESSAGES_PER_SECOND_PER_CHAT
', 'MAX_MESSAGE_LENGTH', 'MaskPosition', 'Message', 'MessageEntity', 'OrderInfo', 'ParseMode', '
PhotoSize', 'PreCheckoutQuery', 'ReplyKeyboardMarkup', 'ReplyKeyboardRemove', 'ReplyMarkup', 'SU
PPORTED_WEBHOOK_PORTS', 'ShippingAddress', 'ShippingOption', 'ShippingQuery', 'Sticker', 'Sticke
rSet', 'SuccessfulPayment', 'TelegramError', 'TelegramObject', 'Update', 'User', 'UserProfilePho
tos', 'Venue', 'Video', 'VideoNote', 'Voice', 'WebhookInfo', '__all__', '__author__', '__builtin
s__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__',
'__spec__', '__version__', 'base', 'bot', 'callbackquery', 'chat', 'chataction', 'chatmember', '
choseninlineresult', 'constants', 'error', 'files', 'forcereply', 'games', 'inline', 'keyboardbu
tton', 'message', 'messageentity', 'parsemode', 'payment', 'replykeyboardmarkup', 'replykeyboard
remove', 'replymarkup', 'update', 'user', 'userprofilephotos', 'utils', 'vendor', 'version', 'we
bhookinfo']
Operating System:
Windows 10 64-bit
Version of Python, python-telegram-bot & dependencies:
$ python -m telegram
python-telegram-bot 8.0
certifi 2017.07.27.1
future 0.16.0
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)]
Hi,
Maybe the script is running in a different environment or python version by accident? As you can see from the dir(telegram) Bot is there and available. I can not reproduce this in any way.
One more thing. Bot.get_me() returns a telegram.User object, not json.
Please try this again in a clean environment to be sure.
Hi Eldinnie,
Many thanks for getting back on this issue.
It is a very strange problem. When I try to run the file in _cmd_, I get the above mentioned error. Then if I type python and on python prompt I try to import "telegram", i get the same error.
However, at this point if I was to open a new _cmd_ window and do an import it works fine. Cannot understand why. Please see the attached screenshot take at same time from two _cmd_ windows.

I will keep digging and let you know if any progress is made. Once again, thanks for your time.
Kind regards,
Mustafa
Hi,
Ok, found the issue. Issue lies in the name of my file which was called test.py
Apparently somewhere it didnt like the file name and after I renamed my file, it worked a charm. So if you are working with this module, please make sure that you do not call any file in your project folder test.py.
Thanks for your time.
When I am running a script that uses telegram bot, encountered with an error:
AttributeError: module 'telegram' has no attribute 'Bot'
import telegram
dir(telegram)
['Telegram', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
python -m telegram
No module named telegram.__main__; 'telegram' is a package and cannot be directly executed
Python 3.6.5
telegram-0.0.1
Windows 10-64bit
@kiddick
We invite you to ask questions about the usage of this library in our Telegram group. In case you are unable to join our group due to Telegram restrictions, you can use our IRC channel to participate in the group.
Since this system is for tracking issues with the library itself, we'll be closing this one.
Most helpful comment
Hi,
Ok, found the issue. Issue lies in the name of my file which was called test.py
Apparently somewhere it didnt like the file name and after I renamed my file, it worked a charm. So if you are working with this module, please make sure that you do not call any file in your project folder test.py.
Thanks for your time.