-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathnew.py
More file actions
72 lines (62 loc) · 2.35 KB
/
new.py
File metadata and controls
72 lines (62 loc) · 2.35 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from pyrogram import Client, filters
from config import API_ID, API_HASH, BOT_TOKEN
import re
# Initialize bot
bot = Client(
"username_to_id",
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN
)
@bot.on_message(filters.command("id"))
async def get_user_id(client, message):
# Check if there's a username in the command
if len(message.command) != 2:
await message.reply_text(
"<blockquote>**❌ Please use the command like this:**\n"
"`/id @username`</blockquote>"
)
return
# Get the username from command
username = message.command[1]
# Remove @ if present
username = username.replace("@", "")
try:
# Try to get user info
user = await client.get_users(username)
# Prepare user information
user_id = user.id
first_name = user.first_name
last_name = user.last_name or ""
mention = f"@{user.username}" if user.username else "No username"
user_type = "Bot" if user.is_bot else "User"
is_premium = "Yes" if user.is_premium else "No"
# Create detailed response
response = (
f"<blockquote>**👤 User Information**</blockquote>\n\n"
f"<blockquote>**Type:** `{user_type}`\n"
f"**ID:** `{user_id}`\n"
f"**Name:** `{first_name} {last_name}`\n"
f"**Username:** `{mention}`\n"
f"**Premium:** `{is_premium}`</blockquote>\n\n"
"<blockquote>🛠 Made with ❤️ By @roxybasicneedbot1</blockquote>"
)
await message.reply_text(response)
except Exception as e:
error_msg = str(e).lower()
if "username not found" in error_msg or "no user" in error_msg:
await message.reply_text(
"<blockquote>**❌ Username not found!**\n\n"
"Please make sure:\n"
"1️⃣ The username exists\n"
"2️⃣ You typed it correctly\n"
"3️⃣ The user has a public profile</blockquote>"
)
else:
await message.reply_text(
"<blockquote>**❌ An error occurred while fetching user information.**\n"
"Please try again later.</blockquote>"
)
if __name__ == "__main__":
print("Starting Username to ID bot...")
bot.run()