How to get_main_list_chats method?
ToyPoodleM opened this issue · 0 comments
I'm going to print out a list of chat rooms on my telegram. However, even if the method is executed, only the <coroutine is returned, so I cannot see the chat_id in the room Please tell me how to check the list of chat rooms
``import asyncio
import logging
from aiotdlib import Client
from aiotdlib.api import API, BaseObject, UpdateNewMessage, ChatLists
API_ID = xxxxx
API_HASH = "xxxx"
PHONE_NUMBER = "xx"
async def on_update_chat_list(client: Client, update: ChatLists):
chat_list = update.chat_lists
logging.info(f'chat list count {chat_list}')
async def on_update_new_message(client: Client, update: UpdateNewMessage, chatlist: ChatLists):
chat_id = update.message.chat_id
# api field of client instance contains all TDLib functions, for example get_chat
chat = await client.api.get_chat(chat_id)
# await client.send_text(update.message.chat_id, "HAVE A GOOD DAY !")
chat_list = chatlist.chat_lists
logging.info(f'Message received in chat {chat.title}')
logging.info(f'Message received in chat {chat.last_message}')
logging.info(f'chat list count {chat_list}')
result = client.get_main_list_chats(100)
logging.info(f'chat list count {result}')
await client.stop();
async def any_event_handler(client: Client, update: BaseObject):
result = client.get_main_list_chats(100)
logging.info(f'Event of type {update.ID} received : {result}' )
async def main():
client = Client(
api_id=API_ID,
api_hash=API_HASH,
phone_number=PHONE_NUMBER
)
# client.add_event_handler(on_update_chat_list, update_type=API.Types.CHAT_LISTS)
# Registering event handler for 'updateNewMessage' event
# You can register many handlers for certain event type
# client.add_event_handler(on_update_new_message, update_type=API.Types.UPDATE_NEW_MESSAGE)
# You can register handler for special event type "*".
# It will be called for each received event
client.add_event_handler(any_event_handler, update_type=API.Types.ANY)
async with client:
# idle() will run client until it's stopped
await client.idle()
if name == 'main':
logging.basicConfig(level=logging.INFO)
asyncio.run(main())