类型错误:send_message() 收到意外的关键字参数“parse_mode”

may*_*ank 0 reddit praw telegram telegram-bot

下面是我用于电报机器人的代码,该机器人从我喜欢的 Reddit 子版块发布新的更新。这不是我的代码(我在堆栈溢出上在线找到它),但我不断收到此错误。我到处搜索但没有找到任何解决方案。无论如何,即使是关于我应该走哪个方向的轻微信息也将不胜感激。

import telebot
import praw
import config
bot_token = 'x'
bot_chatID = '@monsterKing_bot'
bot = telebot.TeleBot(bot_token)

reddit = praw.Reddit(client_id='x', \
                     client_secret='x', \
                     user_agent='x', \
                     username='x ', \
                     password='x')

def reddit_scraper(submission):
    news_data = []
    subreddit = reddit.subreddit('coronavirus')
    new_subreddit = subreddit.new(limit=500)
    for submission in subreddit.new(limit=5):
        data = {}
        data['title'] = submission.title
        data['link'] = submission.url
        news_data.append(data)
    return news_data

def get_msg(news_data):
    msg = '\n\n\n'
    for news_item in news_data:
        title = news_item['title']
        link = news_item['link']
        msg += title+'\n[<a href="'+link+'">Read the full article --></a>]'
        msg += '\n\n'

    return msg

subreddit = reddit.subreddit('coronavirus')
new_subreddit = subreddit.new(limit=500)
for submission in subreddit.new(limit=1):
    news_data = reddit_scraper(submission)
    if len(news_data) > 0:
        msg = get_msg(news_data)
        status = bot.send_message(chat_id='@monsterKing_bot', text=msg, parse_mode=telegram.ParseMode.HTML)        
        if status:            
            print(status)
else:
    print('No updates.')
Run Code Online (Sandbox Code Playgroud)

完整错误消息如下:

Traceback (most recent call last):
  File "c:\Users\mayan\Downloads\redditscraperbot.py", line 42, in <module>
    status = bot.send_message(chat_id='@monsterKing_bot', text=msg, parse_mode=telegram.ParseMode.HTML)
TypeError: send_message() got an unexpected keyword argument 'parse_mode'
Run Code Online (Sandbox Code Playgroud)

小智 6

尝试 pip install pyTelegramBotAPI 而不是 pip install telebot