Answer the question
In order to leave comments, you need to log in
How to make the bot react to the one to whom the command was answered?
Code example:
def uid(arg):
return arg.split()[1]
@bot.message_handler(commands=['kick'])
def kick(message):
if message.from_user.id == 919969181 or message.from_user .id == 737549672 or message.from_user.id == 68806563 :
bot.reply_to(message, 'Yes!')
time.sleep(1)
id = uid(message.text)
bot.kick_chat_member(chat_id=message.chat. id ,user_id=id)
time.sleep(1)
bot.unban_chat_member( chat_id = message.chat.id ,user_id=id, only_if_banned=True)
It needs to kick the one whose message was answered with the command
Answer the question
In order to leave comments, you need to log in
chat_id = message.chat.id
message_id = message.message_id # или message.id - в последних версиях есть такое
if message.reply_to.message is None:
bot.send_message(chat_id=chat_id, "Ответьте командой на сообщение", reply_to_message_id=message_id)
else:
id_to_kick = message.reply_to_message.from_user.id
bot.kick_chat_member(chat_id=chat_id, user_id=id_to_kick)
bot.send_message(chat_id=chat_id, "Пользователь кикнут", reply_to_message_id=message_id)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question