I need to use bot.get_chat_member() in my router in file callbackHandlers.py
I can’t import main to callbackHandlers cuz callbackHandlers where already imported into main and i get import error.
Maybe there is a way to use method getChatMember without bot object?
there is my code
main.py:
<code>import asyncio
from aiogram import Bot, Dispatcher
from aiogram.types import Message
import botConfig
import callbackHandlers, commandHandlers
bot = Bot(botConfig.TOKEN, parse_mode="HTML")
dp = Dispatcher()
dp.include_routers(callbackHandlers.router, commandHandlers.router)
async def main():
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
</code>
<code>import asyncio
from aiogram import Bot, Dispatcher
from aiogram.types import Message
import botConfig
import callbackHandlers, commandHandlers
bot = Bot(botConfig.TOKEN, parse_mode="HTML")
dp = Dispatcher()
dp.include_routers(callbackHandlers.router, commandHandlers.router)
async def main():
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
</code>
import asyncio
from aiogram import Bot, Dispatcher
from aiogram.types import Message
import botConfig
import callbackHandlers, commandHandlers
bot = Bot(botConfig.TOKEN, parse_mode="HTML")
dp = Dispatcher()
dp.include_routers(callbackHandlers.router, commandHandlers.router)
async def main():
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
callbackHandlers.py:
<code>@router.callback_query(F.data == "checkFollow")
async def checkFollowdef(callback: CallbackQuery):
res = await bot.get_chat_member("@somechannel", callback.from_user.id)
await callback.message.answer(f"{res}")
</code>
<code>@router.callback_query(F.data == "checkFollow")
async def checkFollowdef(callback: CallbackQuery):
res = await bot.get_chat_member("@somechannel", callback.from_user.id)
await callback.message.answer(f"{res}")
</code>
@router.callback_query(F.data == "checkFollow")
async def checkFollowdef(callback: CallbackQuery):
res = await bot.get_chat_member("@somechannel", callback.from_user.id)
await callback.message.answer(f"{res}")
and I get NameError:
<code>res = await bot.get_chat_member("@somechannel", callback.from_user.id)
^^^
</code>
<code>res = await bot.get_chat_member("@somechannel", callback.from_user.id)
^^^
</code>
res = await bot.get_chat_member("@somechannel", callback.from_user.id)
^^^
NameError: name ‘bot’ is not defined
New contributor
Emil Nazarchuk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.