Advertisement
oort77

telegram bot

Jul 12th, 2022
1,496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. # Telegram Bot
  2. # pip install pyTelegramBotAPI
  3. import telebot
  4. bot = telebot.TeleBot('YOUR TOKEN')
  5. # send message
  6. bot.send_message(chat_id='YOUR ID', text='Medium.com')
  7. # send photo
  8. bot.send_photo(chat_id='YOUR ID', photo=open('photo.jpg', 'rb'))
  9. # send audio
  10. bot.send_audio(chat_id='YOUR ID', audio=open('audio.mp3', 'rb'))
  11. # send document
  12. bot.send_document(chat_id='YOUR ID', document=open('document.pdf', 'rb'))
  13. # send video
  14. bot.send_video(chat_id='YOUR ID', video=open('video.mp4', 'rb'))
  15. # Reply handler
  16. @bot.message_handler(commands=['start', 'about', 'help'])
  17. def send_welcome(msg):
  18.     bot.reply_to(msg, "Welcome to Medium.com")
  19. # Reply all Handler
  20. @bot.message_handler(func=lambda msg: True)
  21. def echo_all(msg):
  22.     bot.reply_to(msg, msg.text)
  23. # Ban Member handler
  24. @bot.message_handler(commands=['ban'])
  25. def ban_member(msg):
  26.     bot.kick_chat_member(chat_id=msg.chat.id, user_id=msg.from_user.id)
  27.     bot.reply_to(msg, "You have been banned")
  28. bot.infinity_polling()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement