dayod
dayod

Reputation: 86

If the message is a reply, bot should get id of a user

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

Upvotes: 2

Views: 1741

Answers (2)

user13699857
user13699857

Reputation:

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

Upvotes: 0

Mehdi Mostafavi
Mehdi Mostafavi

Reputation: 880

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.

Upvotes: 2

Related Questions