Hello!
I'm encountering an issue while using the aiogram library to create a Telegram bot. Currently, I'm using the following code:
# Imports and settings
async def main():
bot = Bot(token=config.token_bot.get_secret_value(), parse_mode=ParseMode.HTML)
dp = Dispatcher()
# Bot and dispatcher setup
main_admin = config_manager.get_value("main_admin")
asyncio.create_task(send_stream_notification(bot))
await bot.send_message(chat_id=main_admin,
text="➖➖➖ Bot has connected to the network ➖➖➖\n"
"<b>In case of any issues or questions, please contact @michailcoding, your reliable technical companion.</b>")
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
I also have a send_stream_notification file in which the send_stream_notification(bot) function looks like this:
# Imports and function
async def send_stream_notification(bot):
alert_text = ded("""
<b>{stream_title}</b>
➖➖➖➖➖
{stream_viewers}
➖➖➖➖➖
{i['description']}
➖➖➖➖➖
<i>Category - {category_title}</i>
""")
await bot.send_photo(photo=URLInputFile("https://wp-s.ru/wallpapers/9/13/535270747480065/oslepitelnaya-priroda-vokrug-gor.jpg"), chat_id=-1001972564538, caption=alert_text)
However, upon running this, I'm encountering an error
current: Optional[ContextInstance] = cls.__context_instance.get()
LookupError: <ContextVar name='instance_Bot' at 0x0000024D32006ED0
I understand that the code is temporarily shortened and there might be some omissions in the code provided above, but the issue remains. This error occurs when I try to run the send_stream_notification function using asyncio.create_task(send_stream_notification(bot)). I hope you can help me identify the root cause of this problem and provide guidance on how to resolve it.
Thank you in advance for your assistance!
versions modules
aiogram==3.0.0b7
I tried reworking the code to a simple bot.send_message, and strangely enough, the bot worked. But when sending a photo via a link, a problem appeared. URLInputFile is imported from aiogram.types for links. And immediately an error pops up. As did not try to change the code in run, does not help. Please help me.
This function will be infinite in the future, but at the moment I'm testing sending an image that doesn't work