簡體   English   中英

ImportError:無法從“電報”(未知位置)導入名稱“Bot”

[英]ImportError: cannot import name 'Bot' from 'telegram' (unknown location)

我開始使用 python 對一個電報機器人進行編程,並在第一個代碼中存儲:

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()

但我得到這個錯誤:

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)

我讀了文件,但我無法修復它!

首先,您不應該在此處發布您的令牌密鑰。 而且我認為錯誤出現在 function 聲明中。 您還應該導入“CallbackContext”並使用“update.message.reply_text”(而不是 bot.sendMessage)。 看看項目主頁中的這個“ Hello World bot ”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM