1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to get group_id when telegram bot is added to that group using aiogram?

Discussão em 'Python' iniciado por Stack, Setembro 28, 2024 às 03:12.

  1. Stack

    Stack Membro Participativo

    bot = Bot(token=TOKEN)
    dp = Dispatcher()
    chat_ids = []

    async def check_if_bot_is_admin(chat_id):
    member = await bot.get_chat_member(chat_id, bot.id)
    resp = member.status
    return resp

    @dp.message(F.photo)
    async def handle_photo(message: types.Message):
    for group_id in chat_ids:
    is_admin = await check_if_bot_is_admin(group_id)
    if message.chat.type == 'private' and is_admin:
    await message.copy_to(chat_id=group_id)
    async def main():
    await dp.start_polling(bot)


    As you can see, after running this code, when you send an image to a bot as a private message, the bot starts to send to the group that are in a list of chat_ids (and before it check if it has admin). But now I need to fill this chat_ids list manually. I can't figure out how to automatically append any id of a group after a bot is added to that group.

    My aim for making this bot is to make sure that after sending any image as a private message to a bot, it sends the image to all group that it has admin.

    Continue reading...

Compartilhe esta Página