@borg.on(admin_cmd('broadcast ?(.*)', allow_sudo=True))
async def _(event):
    if event.fwd_from:
        return
    if (not event.is_reply):
        (await event.edit('Reply to a message to broadcast.'))
        return
    channels = get_all_channels()
    error_count = 0
    sent_count = 0
    (await event.edit('Sending....'))
    if event.reply_to_msg_id:
        previous_message = (await event.get_reply_message())
        if (previous_message.sticker or previous_message.poll):
            (await event.edit('Reply .forward for stickers and polls.'))
            return
        if (previous_message.gif or previous_message.audio or previous_message.voice or previous_message.video or previous_message.video_note or previous_message.contact or previous_message.game or previous_message.geo or previous_message.invoice):
            (await event.edit('Not supported. Try .forward'))
            return
        if ((not previous_message.web_preview) and previous_message.photo):
            file = (await borg.download_file(previous_message.media))
            uploaded_doc = (await borg.upload_file(file, file_name='img.png'))
            raw_text = previous_message.text
            for channel in channels:
                try:
                    if previous_message.photo:
                        (await borg.send_file(int(channel.chat_id), InputMediaUploadedPhoto(file=uploaded_doc), force_document=False, caption=raw_text, link_preview=False))
                    sent_count += 1
                    (await event.edit(f'''Sent : {sent_count}
Error : {error_count}
Total : {len(channels)}'''))
                except Exception as error:
                    try:
                        (await borg.send_message(logs_id, f'Error in sending at {chat_id}.'))
                        (await borg.send_message(logs_id, ('Error! ' + str(error))))
                        if (error == 'The message cannot be empty unless a file is provided'):
                            event.edit('For sending files, upload in Saved Messages and reply .forward to in.')
                            return
                    except:
                        pass
                    error_count += 1
                    (await event.edit(f'''Sent : {sent_count}
Error : {error_count}
Total : {len(channels)}'''))
            (await event.edit(f'{sent_count} messages sent with {error_count} errors.'))
            if (error_count > 0):
                try:
                    (await borg.send_message(logs_id, f'{error_count} Errors'))
                except:
                    pass
        else:
            raw_text = previous_message.text
            for channel in channels:
                try:
                    (await borg.send_message(int(channel.chat_id), raw_text, link_preview=False))
                    sent_count += 1
                    (await event.edit(f'''Sent : {sent_count}
Error : {error_count}
Total : {len(channels)}'''))
                except Exception as error:
                    try:
                        (await borg.send_message(logs_id, f'Error in sending at {channel.chat_id}.'))
                        (await borg.send_message(logs_id, ('Error! ' + str(error))))
                        if (error == 'The message cannot be empty unless a file is provided'):
                            event.edit('For sending files, upload in Saved Messages and reply .forward to in.')
                            return
                    except:
                        pass
                    error_count += 1
                    (await event.edit(f'''Sent : {sent_count}
Error : {error_count}
Total : {len(channels)}'''))
            (await event.edit(f'{sent_count} messages sent with {error_count} errors.'))
            if (error_count > 0):
                try:
                    (await borg.send_message(logs_id, f'{error_count} Errors'))
                except:
                    (await event.edit('Set up log channel for checking errors.'))
@borg.on(admin_cmd('broadcast ?(.*)', allow_sudo=True))
async def _(event):
    if event.fwd_from:
        return
    if (not event.is_reply):
        (await event.edit('Reply to a message to broadcast.'))
        return
    channels = get_all_channels()
    error_count = 0
    sent_count = 0
    (await event.edit('Sending....'))
    if event.reply_to_msg_id:
        previous_message = (await event.get_reply_message())
        if (previous_message.sticker or previous_message.poll):
            (await event.edit('Reply .forward for stickers and polls.'))
            return
        if (previous_message.gif or previous_message.audio or previous_message.voice or previous_message.video or previous_message.video_note or previous_message.contact or previous_message.game or previous_message.geo or previous_message.invoice):
            (await event.edit('Not supported. Try .forward'))
            return
        if ((not previous_message.web_preview) and previous_message.photo):
            file = (await borg.download_file(previous_message.media))
            uploaded_doc = (await borg.upload_file(file, file_name='img.png'))
            raw_text = previous_message.text
            for channel in channels:
                try:
                    if previous_message.photo:
                        (await borg.send_file(int(channel.chat_id), InputMediaUploadedPhoto(file=uploaded_doc), force_document=False, caption=raw_text, link_preview=False))
                    sent_count += 1
                    (await event.edit(f'Sent : {sent_count}
Error : {error_count}
Total : {len(channels)}'))
                except Exception as error:
                    try:
                        (await borg.send_message(logs_id, f'Error in sending at {chat_id}.'))
                        (await borg.send_message(logs_id, ('Error! ' + str(error))))
                        if (error == 'The message cannot be empty unless a file is provided'):
                            event.edit('For sending files, upload in Saved Messages and reply .forward to in.')
                            return
                    except:
                        pass
                    error_count += 1
                    (await event.edit(f'Sent : {sent_count}
Error : {error_count}
Total : {len(channels)}'))
            (await event.edit(f'{sent_count} messages sent with {error_count} errors.'))
            if (error_count > 0):
                try:
                    (await borg.send_message(logs_id, f'{error_count} Errors'))
                except:
                    pass
        else:
            raw_text = previous_message.text
            for channel in channels:
                try:
                    (await borg.send_message(int(channel.chat_id), raw_text, link_preview=False))
                    sent_count += 1
                    (await event.edit(f'Sent : {sent_count}
Error : {error_count}
Total : {len(channels)}'))
                except Exception as error:
                    try:
                        (await borg.send_message(logs_id, f'Error in sending at {channel.chat_id}.'))
                        (await borg.send_message(logs_id, ('Error! ' + str(error))))
                        if (error == 'The message cannot be empty unless a file is provided'):
                            event.edit('For sending files, upload in Saved Messages and reply .forward to in.')
                            return
                    except:
                        pass
                    error_count += 1
                    (await event.edit(f'Sent : {sent_count}
Error : {error_count}
Total : {len(channels)}'))
            (await event.edit(f'{sent_count} messages sent with {error_count} errors.'))
            if (error_count > 0):
                try:
                    (await borg.send_message(logs_id, f'{error_count} Errors'))
                except:
                    (await event.edit('Set up log channel for checking errors.'))