K
K
Kiril-cloud2021-06-06 11:59:35
Python
Kiril-cloud, 2021-06-06 11:59:35

How do I call the asynchronous aiogram function dp.register_message_handler(...)?

There is an aiogram bot, but it has a function for sending from a telegram client

async def send_message(url):	
  api_id = ххххххххххх
  api_hash = 'хххххххххххххххххххх'
  client = TelegramClient('TeleSender', api_id, api_hash)
  await client.start()
  channel = await client.get_entity(url)
  c = await client.get_participants(channel, limit=50000)	
  for user in c:
     try:
     	u = user.username
     	await client.send_message(u, 'Тестовая рассылка.')
     except Exception as e:
     	print(e)

How do I call this function via dp.register_message_handler()

When I call it like this:
@dp.message_handler()
async def messages(message):
  if message.text == 'Заказать рассылку':
    await message.reply( 'Пришлите ссылку на канал или чат с целевой аудиторией для рассылки')
    dp.register_message_handler(message.text, send_message)

Gives an error message:
TypeError('unsupported callable') from ex TypeError: unsupported callable

I tried adding await before dp.register_message_handler(...):
await dp.register_message_handler(message.text, send_message)

And inside it when I call the function:
dp.register_message_handler(message.text, await send_message)

And even like this:
dp.register_message_handler(await send_message(message.text))

Still an error

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question