0x0001
1.獲取token
依次輸入:
/start
/newbot
# 然后輸入機器人的名字,注意必須以 bot 結尾!
# `987654321:FEDCBA_dfoiuweSWEczgxT7-l4r9Y` 收到類似這樣的就是你的token
2.獲取個人chat_id
其中id字段,就是你的chat_id
3.獲取群組chat_id
- 第一種方式
把你創建的機器人拉到群組里,然后@你的機器人並隨意發送一條信息,然后訪問 https://api.telegram.org/bot<token>/getUpdates
獲取,-100
開頭的id就是.
- 第二種方式
添加機器人 @get_id_bot
到你的頻道,正常情況他會自動發言告訴你頻道ID,如果沒有發言,可以在群組內輸入 /my_id@get_id_bot
獲取ID.
注意在ID前添加 -100
0x0002
python代碼示例
# coding:utf-8
# @創建者:jonnyan404
# 日期:2021-02-13
# 博客地址:www.mrdoc.fun
# pip3 install pyTelegramBotAPI
import telebot
from telebot import apihelper
def push_telegram(text):
token = '15xxxx62:xxxxxxx'
mrdoc_id = '-10013xxxxxx'
bot = telebot.TeleBot(token)
apihelper.proxy = {
'http': 'http://127.0.0.1:10809',
'https': 'http://127.0.0.1:10809'
}
bot.send_message(mrdoc_id, text, parse_mode="Markdown")
if __name__ == '__main__':
text='*2021,扭轉乾坤!*,[收藏發大財](https://www.mrdoc.fun),[https://www.cnblogs.com/jonnyan/p/14399638.html](https://www.cnblogs.com/jonnyan/p/14399638.html)'
push_telegram(text)