我对telegram_bot完全陌生。我想在以下代码中执行bot.send_message()
(如代码中所注释),但是不能这样做。请帮忙。
!pip install python-telegram-bot --upgrade
import telegram
bot = telegram.Bot(token='**************')
bot.send_message(chat_id='******', text="I'm sorry Dave I'm afraid I can't do that.")
错误提示为:
1 bot.send_message('mardepbot',"I'm sorry Dave I'm afraid I can't do that.")
/usr/local/lib/python3.6/dist-packages/telegram/bot.py in decorator(self, *args, **kwargs)
63 def decorator(self, *args, **kwargs):
64 logger.debug('Entering: %s', func.__name__)
---> 65 result = func(self, *args, **kwargs)
66 logger.debug(result)
67 logger.debug('Exiting: %s', func.__name__)
/usr/local/lib/python3.6/dist-packages/telegram/bot.py in decorator(self, *args, **kwargs)
88 data['reply_markup'] = reply_markup
89
---> 90 result = self._request.post(url, data, timeout=kwargs.get('timeout'))
91
92 if result is True:
/usr/local/lib/python3.6/dist-packages/telegram/utils/request.py in post(self, url, data, timeout)
307 result = self._request_wrapper('POST', url,
308 body=json.dumps(data).encode('utf-8'),
--> 309 headers={'Content-Type': 'application/json'})
310
311 return self._parse(result)
/usr/local/lib/python3.6/dist-packages/telegram/utils/request.py in _request_wrapper(self, *args, **kwargs)
221 raise Unauthorized(message)
222 elif resp.status == 400:
--> 223 raise BadRequest(message)
224 elif resp.status == 404:
225 raise InvalidToken()
BadRequest: Chat not found
答案 0 :(得分:0)
我刚刚解决了类似的问题。请检查:
答案 1 :(得分:0)
您不能将消息发送到字符串 ('mardepbot') 作为地址。如果 mardepbot 是你正在使用的机器人,那么你犯了 2 个错误;那你应该用自己的ID给自己发消息。