-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelethon_debug_script.py
More file actions
74 lines (62 loc) · 2.91 KB
/
Copy pathtelethon_debug_script.py
File metadata and controls
74 lines (62 loc) · 2.91 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
73
74
import asyncio
import os
from dotenv import load_dotenv
from telethon import TelegramClient
from telethon.errors import ChannelPrivateError, ChatAdminRequiredError
# --- INSTRUCTIONS ---
# 1. Make sure your .env file is filled out correctly.
# 2. Run this script from your terminal: python3 debug_telethon.py
# 3. The first time, Telethon will ask you to log in with the phone number
# associated with your API_ID and API_HASH. You may need to enter a code.
# 4. Paste the ENTIRE output from the terminal back to me.
# --------------------
async def main():
print("--- Starting Telethon Debug Script ---")
load_dotenv()
# Load credentials from .env file
api_id = os.getenv('TELEGRAM_API_ID')
api_hash = os.getenv('TELEGRAM_API_HASH')
# --- IMPORTANT: Manually enter the chat ID here ---
# Use the exact same ID that is in your config.json file
chat_id_to_test = -1003186721189
# --------------------------------------------------
if not api_id or not api_hash:
print("[ERROR] TELEGRAM_API_ID or TELEGRAM_API_HASH not found in .env file.")
return
# We use a different session name to force a clean login
client = TelegramClient('debug_session', int(api_id), api_hash)
try:
print("Connecting to Telegram as user...")
await client.start()
print("Client started successfully.")
print(f"Attempting to find entity for chat ID: {chat_id_to_test}...")
entity = await client.get_entity(chat_id_to_test)
print("\n" + "#"*20 + " SUCCESS! " + "#"*20)
print(f"Successfully found the entity! The problem is likely solved.")
print(f" - Channel Name: {entity.title}")
print(f" - Type: {type(entity).__name__}")
print("You can now try running the main bot again.")
print("#"*50 + "\n")
except (ValueError, TypeError) as e:
print("\n" + "#"*20 + " ERROR! " + "#"*20)
print(f"[CRITICAL] The chat ID {chat_id_to_test} is invalid. It must be an integer.")
print(f"[DEBUG] Error: {e}")
print("#"*48 + "\n")
except (ChannelPrivateError, ChatAdminRequiredError) as e:
print("\n" + "#"*20 + " ERROR! " + "#"*20)
print(f"[CRITICAL] You do not have permission to access this channel.")
print(" The user account you logged in with is NOT a member of the channel.")
print(f"[DEBUG] Error: {e}")
print("#"*48 + "\n")
except Exception as e:
print("\n" + "#"*20 + " ERROR! " + "#"*20)
print(f"[CRITICAL] A general error occurred. This often means the Chat ID is wrong or you are not in the channel.")
print(f"[DEBUG] Error Type: {type(e).__name__}")
print(f"[DEBUG] Error: {e}")
print("#"*48 + "\n")
finally:
if client.is_connected():
await client.disconnect()
print("--- Debug script finished. ---")
if __name__ == "__main__":
asyncio.run(main())