I started programming a telegram bot with python right know and stocked at the first code:
from telegram.ext import Updater, CommandHandler
updater = Updater('1670111367:AAHEzzfNQUeWL9ylptnDyQPZjarACLNUcGc')
def start(bot,update):
chat_id=update.message.chat_id
bot.sendMessage(chat_id,"hello")
start_command=CommandHandler('start',start)
updater.dispatcher.add_handler(start_command)
updater.start_polling()
updater.idle()
but I get this Error:
Traceback (most recent call last):
File "/home/smjt2000/Programming/Projects/Telegram_Bot/1.py", line 1, in <module>
from telegram.ext import Updater, CommandHandler
File "/home/smjt2000/.local/lib/python3.8/site-packages/telegram/ext/__init__.py", line 21, in <module>
from .basepersistence import BasePersistence
File "/home/smjt2000/.local/lib/python3.8/site-packages/telegram/ext/basepersistence.py", line 25, in <module>
from telegram import Bot
ImportError: cannot import name 'Bot' from 'telegram' (unknown location)
I read the documents but I can't fix it!!!
First, you should not post your token key here. And I think the error is on the function declaration. You should also import "CallbackContext" and use "update.message.reply_text" (instead of bot.sendMessage). Take a look at this " Hello World bot " in the main page of the project.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.