我正在尝试启动电报机器人,但出现以下错误:
bars@MacBook-Pro-Lisa desktop % python3 telegram_bot.py
Traceback (most recent call last):
File "/Users/bars/Desktop/telegram_bot.py", line 30, in <module>
updater = Updater(token=TOKEN, use_context=True)
TypeError: Updater.__init__() got an unexpected keyword argument 'token'
我重新安装了python,下载了所有必要的库,仔细检查了文件中的代码,还是不行。这是文件中的代码:
import telegram
from telegram.ext import Updater, MessageHandler, filters
# Enter your Telegram API token here
TOKEN = '5921926845:AAGk_ffGmBlONkxRY81til-4WoCbREE9kWA'
# Enter the message you want the bot to post as a comment
MESSAGE = 'Огонь'
# Enter the ID of the channel you want to monitor
CHANNEL_ID = '-1001888862097'
# Enter your Telegram chat ID here to receive forwarded posts
YOUR_CHAT_ID = '-1001841147699'
# Create a bot instance using your Telegram API token
bot = telegram.Bot(token=TOKEN)
# Define a function to handle new channel posts
def handle_post(update, context):
# Check if the new post is from the channel you want to monitor
if update.channel_post.chat.id == CHANNEL_ID:
# Post your message as a comment on the new post
bot.send_message(chat_id=CHANNEL_ID, text=MESSAGE, reply_to_message_id=update.channel_post.message_id)
# Forward the new post to yourself
bot.forward_message(chat_id=YOUR_CHAT_ID, from_chat_id=CHANNEL_ID, message_id=update.channel_post.message_id)
# Create an updater instance using your Telegram API token
updater = Updater(token=TOKEN, use_context=True)
# Set up a message handler to handle new channel posts
updater.dispatcher.add_handler(MessageHandler(Filters.channel, handle_post))
# Start the updater
updater.start_polling()
# Keep the script running
updater.idle()
什么地方出了问题?是文件代码有误还是系统有问题?马科斯比格苏尔