-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy_tg_bot_api.py
More file actions
37 lines (27 loc) · 967 Bytes
/
py_tg_bot_api.py
File metadata and controls
37 lines (27 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Telegram Bot
# pip install pyTelegramBotAPI
import telebot
bot = telebot.TeleBot('YOUR TOKEN')
# send message
bot.send_message(chat_id='YOUR ID', text='Medium.com')
# send photo
bot.send_photo(chat_id='YOUR ID', photo=open('photo.jpg', 'rb'))
# send audio
bot.send_audio(chat_id='YOUR ID', audio=open('audio.mp3', 'rb'))
# send document
bot.send_document(chat_id='YOUR ID', document=open('document.pdf', 'rb'))
# send video
bot.send_video(chat_id='YOUR ID', video=open('video.mp4', 'rb'))
# Reply handler
@bot.message_handler(commands=['start', 'about', 'help'])
def send_welcome(msg):
bot.reply_to(msg, "Welcome")
# Reply all Handler
@bot.message_handler(func=lambda msg: True)
def echo_all(msg):
bot.reply_to(msg, msg.text)
# Ban Member handler
@bot.message_handler(commands=['ban'])
def ban_member(msg):
bot.kick_chat_member(chat_id=msg.chat.id, user_id=msg.from_user.id)
bot.reply_to(msg, "You have been banned")bot.infinity_polling()