Код: Выделить всё
from telegram import Bot
import asyncio
TOKEN = "blah"
CHAT_ID = 1
async def send_message_async():
message = "This is a test update from the bot!"
bot = Bot(token=TOKEN)
await bot.send_message(chat_id=CHAT_ID, text=message)
print("Message sent successfully!")
async def main():
print("Before sending message...")
await send_message_async()
print("After sending message...") # I don't want this to be blocked until the message is sent
if __name__ == "__main__":
asyncio.run(main())
Я надеюсь найти более простой API для решения вышеуказанной проблемы. Примерно так:
Код: Выделить всё
def send_message():
# Sends message to user asynchonously without blocking the main thread
pass
def main():
# Main function
send_message()
Подробнее здесь: https://stackoverflow.com/questions/786 ... ain-thread