我在 Python 中有以下代码,用于从机器人向我自己发送消息。
import requests
token = '123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI'
method = 'sendMessage'
myuserid = 1949275XX
response = requests.post(
url='https://api.telegram.org/bot{0}/{1}'.format(token, method),
data={'chat_id': myuserid, 'text': 'hello friend'}
).json()
print(response)
但这会返回 {'description': 'Bad Request: chat not found', 'error_code': 400, 'ok': False}
我做错了什么?我通过将 /getid
发送到 @myidbot
获得了 myuserid
并且我从 @BotFather
最佳答案
正如@maak 所指出的,您需要先向机器人发送消息,然后机器人才能向您发送消息。
关于python - Telegram Bot "chat not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41174831/