File size: 1,622 Bytes
95ec5e4 a5ac0a9 95ec5e4 a5ac0a9 95ec5e4 a5ac0a9 95ec5e4 a5ac0a9 95ec5e4 a5ac0a9 95ec5e4 a5ac0a9 95ec5e4 41d9e45 95ec5e4 a5ac0a9 41d9e45 a5ac0a9 95ec5e4 a5ac0a9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
from pyrogram import filters
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
from DragMusic import app
@app.on_message(filters.command("id") & filters.group)
async def id_handler(client, message: Message):
group_id = message.chat.id
user = None
show_group_id = False
# Case 1: If replying to a message with a user
if message.reply_to_message and message.reply_to_message.from_user:
user = message.reply_to_message.from_user
# Case 2: If user is mentioned with @username
elif len(message.command) > 1:
username = message.command[1].replace("@", "")
try:
user = await client.get_users(username)
except Exception:
return await message.reply_text("Invalid username or user not found.")
# Case 3: If no reply or mention, show command sender + group ID
else:
user = message.from_user
show_group_id = True
user_id = user.id
name = user.first_name or "Unknown"
if show_group_id:
text = (
f"User: {name}\n"
f"User ID: {user_id}\n"
f"Group ID: {group_id}"
)
buttons = [
[
InlineKeyboardButton("User ID", copy_text=str(user_id)),
InlineKeyboardButton("Group ID", copy_text=str(group_id)),
]
]
else:
text = f"User: {name}\nUser ID: {user_id}"
buttons = [
[InlineKeyboardButton("User ID", copy_text=str(user_id))]
]
await message.reply(
text,
reply_markup=InlineKeyboardMarkup(buttons)
)
|