How can I make it so that the administrator can indicate the reason for the ban and then the bot indicated this in the chat? Example: "!ban @NAMEorID Spam" From bot to chat: "User NAME banned. Reason – REASON"
@dp.message_handler(AdminFilter(is_chat_admin=True), IsReplyFilter(is_reply=True), commands=['ban'],
commands_prefix='!', chat_type=[types.ChatType.SUPERGROUP, types.ChatType.GROUP])
async def ban(message: types.Message):
replied_user = message.reply_to_message.from_user.id
admin_id = message.from_user.id
await bot.kick_chat_member(chat_id=message.chat.id, user_id=replied_user)
await bot.delete_message(chat_id=message.chat.id, message_id=message.message_id)
await bot.send_message(chat_id=message.chat.id, text=f"[{message.reply_to_message.from_user.full_name}]"
f"(tg://user?id={replied_user})"
f" was banned ",
parse_mode=types.ParseMode.MARKDOWN)
2
Answers
you can use
command, username, reason = message.text.split()
to get args from command!ban @NAMEorID Spam
then you’ll have this argscommand = '!ban'
,username = '@NAMEorID'
,reason = 'Spam'
If you want to reply on message with command "!ban reason", try this: