skip to Main Content

I am doing a bot-moderator. I am doing a command ‘ban’. if I reply to somebody’s message by typing /ban bot should get its id and restrict him.
my code now:

@bot.messsage_handler(commands=['ban'])

def ban(message):

    #here I should get the id of a user which I replied in Telegram
    #then bot should restrict him.

PyTelegramBotApi

python 3.7

thank you

2

Answers


  1. You can restrict user at least at 30 seconds.
    code to restrict:

    bot.restrict_chat_member(message.chat.id, 
                             message.from_user.id, 
                             can_send_messages=False, 
                             until_date=int(time.time())+30)
    #you can replace 30(seconds) by more.
    

    unix time

    Login or Signup to reply.
  2. In Message class, you have a reply_to_message which returns a Message object and you can find user id from this object. If user doesn’t reply to any message it’s equal to None. So this is what you want: message.reply_to_message.from_user

    If you want more information you can read from Telegram bot API or check types.py in library github.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search