Python編寫一個自己的Telegram Bot

Python · 01-07 · 208 人浏览
Python編寫一個自己的Telegram Bot

1.申請一個機器人
TG搜尋BotFather,申請一個機器人,獲取token

2.獲取用戶ID
userinfobot

2.Python編寫以下代碼:

import telegram
import asyncio
async def send_message():
   bot = telegram.Bot(token='')# 機器人Token
   chat_id = ''  # 用户的聊天 ID

   await bot.send_message(chat_id=chat_id, text='Hello, World!')

# 创建一个异步事件循环并运行异步函数

loop = asyncio.get_event_loop()
loop.run_until_complete(send_message())
Python
本站立足于美利堅合衆國,請讀者自覺遵守當地法律!如有違規,本站不承擔任何法律責任! This site is based in the United States of America, readers are requested to abide by local laws! If there are any violations, this site does not bear any legal responsibility! Theme Jasmine by Kent Liao