Telegram bot ban 系统的问题
The problem with the Telegram bot ban system
我怎样才能让管理员可以指出禁止的原因,然后机器人在聊天中指出这个?示例:“!ban @NAMEorID Spam” 从 bot 到聊天:“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)
您可以使用 command, username, reason = message.text.split()
从命令 !ban @NAMEorID Spam
获取参数,然后您将获得此参数 command = '!ban'
、username = '@NAMEorID'
、reason = 'Spam'
@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):
command, username, reason = message.text.split()
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"User {username} banned. Reason - {reason}")
如果您想使用命令“!ban 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):
command, reason = message.text.split()
user_chat: types.Chat = await bot.get_chat(message.reply_to_message.from_user.id)
await message.chat.kick(user_chat.id)
await message.delete()
await message.answer(f"User @{user_chat.username} banned. Reason - {reason}")
我怎样才能让管理员可以指出禁止的原因,然后机器人在聊天中指出这个?示例:“!ban @NAMEorID Spam” 从 bot 到聊天:“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)
您可以使用 command, username, reason = message.text.split()
从命令 !ban @NAMEorID Spam
获取参数,然后您将获得此参数 command = '!ban'
、username = '@NAMEorID'
、reason = 'Spam'
@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):
command, username, reason = message.text.split()
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"User {username} banned. Reason - {reason}")
如果您想使用命令“!ban 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):
command, reason = message.text.split()
user_chat: types.Chat = await bot.get_chat(message.reply_to_message.from_user.id)
await message.chat.kick(user_chat.id)
await message.delete()
await message.answer(f"User @{user_chat.username} banned. Reason - {reason}")