skip to Main Content

Below is the code that I use for a telegram bot that posts new updates from my preferred subreddit. This is not my code (I found it online on stack overflow) but I keep getting this error. I’ve searched everywhere but there wasn’t any solution I could find. Anyway here it is, even slight information of which direction should I go would be greatly appreciated.

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 = 'nnn'
    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 += 'nn'

    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.')

Full error message below:

Traceback (most recent call last):
  File "c:UsersmayanDownloadsredditscraperbot.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'

2

Answers


  1. Chosen as BEST ANSWER

    My chat id was wrong. Chat id is a number we can get from another bot (userinfobot)

    chat_id= 1261748gd278 not chat_id=@name...


  2. try pip install pyTelegramBotAPI instead of pip install telebot

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search