Spaces:
Paused
Paused
""" | |
Plugin to set a custom admin title in a supergroup using /title <user> <title>. | |
Only group owner and admins can use this command. | |
Usable by the bot (not userbot). | |
""" | |
from pyrogram import filters | |
from pyrogram.types import Message | |
from DragMusic import app | |
async def is_admin(client, chat_id, user_id): | |
member = await client.get_chat_member(chat_id, user_id) | |
return member.status in ("administrator", "creator") | |
async def set_admin_title(client, message: Message): | |
if not await is_admin(client, message.chat.id, message.from_user.id): | |
await message.reply_text("Only group admins and the owner can use this command.") | |
return | |
if len(message.command) < 3: | |
await message.reply_text("Usage: /title <user> <title>") | |
return | |
user = message.command[1] | |
title = " ".join(message.command[2:]) | |
try: | |
# Try to get user_id from mention, username, or ID | |
if message.reply_to_message: | |
user_id = message.reply_to_message.from_user.id | |
else: | |
try: | |
user_id = int(user) | |
except ValueError: | |
user_obj = await client.get_users(user) | |
user_id = user_obj.id | |
await client.set_administrator_title(message.chat.id, user_id, title) | |
await message.reply_text(f"Successfully set admin title to: {title}") | |
except Exception as e: | |
await message.reply_text(f"Failed to set admin title: {e}") |