如何找出知道他的名字(@name)的电报用户ID(telebot库)
主页
/
user-364902
Mr. Omega's questions
是否可以将 QProgressBar 放在 QMessageBox 中?
错误代码:
/home/omega/Рабочий стол/#Code/Python/Telegrame_Bot_SATI/Sati.py:30: TelegramDeprecationWarning: Old Handler API is deprecated - see https://git.io/fxJuV for details
bot = bot,
Traceback (most recent call last):
File "/home/omega/Рабочий стол/#Code/Python/Telegrame_Bot_SATI/Sati.py", line 40, in <module>
main()
File "/home/omega/Рабочий стол/#Code/Python/Telegrame_Bot_SATI/Sati.py", line 34, in main
updater.dispatcher.add_handler(handler)
NameError: name 'updater' is not defined
发生错误的部分:
def main():
bot = Bot(
token = TG_TOKEN,
)
update = Updater(
bot = bot,
)
handler = MessageHandler(Filters.all, message_handler)
updater.dispatcher.add_handler(handler)
updater.start_polling()
updater.idle()
这是整个代码
from telegram import Bot
from telegram import Update
from telegram.ext import Updater
from telegram.ext import MessageHandler
from telegram.ext import Filters
TG_TOKEN = "1000229483:AAE4UzZeIgc1NSuN16u1I9wp5j4ZRQoJwEc"
def message_handler(bot: Bot, update: Update):
user = update.effective_user
if user:
neme= user.first_name
else:
name = "Аноним"
text = update.effective_message.text
reply_text = f"Привет, {name}!\n\n{text}"
bot.send_message(
chat_id = update.effective_message.chat_id,
text = reply_text,
)
def main():
bot = Bot(
token = TG_TOKEN,
)
update = Updater(
bot = bot,
)
handler = MessageHandler(Filters.all, message_handler)
updater.dispatcher.add_handler(handler)
updater.start_polling()
updater.idle()
if __name__ == "__main__":
main()