-2

I don't understand what is my mistake. Can someone show me the correct code

My code:

@dp.message_handler(content_types=['text'])
async def Text(update):
    dl = downloader.tiktok_downloader()
    global last_use
    meseg = update.message.text
    getvid = dl.musicaldown(url=meseg,output_name='video.mp4')
    if getvid:
        bot.send_video()
        return
    if getvid == False:
                getvid = dl.ttscraper(url=meseg, output_name="video.mp4")
                if getvid:
                    bot.send_videoo()
                    return
                else:
                    bot.send_message('"failed to download video.check link and try again"')
                    return

My wrong:

    meseg = update.message.text
AttributeError: 'Message' object has no attribute 'message'

i try to change function. but idk how

Alex
  • 3
  • 2
  • Welcome to Stack Overflow. In your own words, where the code says `update.message.text`, what do you expect that to mean, and why? What do you think `update` will be, and why should it have a `message` attribute? (Do you understand what "attribute" means?) What actually is the question - what are you confused about? – Karl Knechtel Feb 10 '23 at 01:25

1 Answers1

-1
@dp.message_handler(content_types=['text'])
async def text_handler(message: types.Message):
    dl = downloader.tiktok_downloader()
    meseg = message.text
    getvid = dl.musicaldown(url=meseg, output_name='video.mp4')
    if getvid:
        with open("video.mp4", "rb") as f:
            await bot.send_video(chat_id=message.chat.id, video=f)
        return
    if getvid == False:
        getvid = dl.ttscraper(url=meseg, output_name="video.mp4")
        if getvid:
            with open("video.mp4", "rb") as f:
                await bot.send_video(chat_id=message.chat.id, video=f)
            return
        else:
            await bot.send_message(chat_id=message.chat.id, text='"failed to download video.check link and try again"')
            return
Alex
  • 3
  • 2
6c00h
  • 89
  • 8
  • @Alex that's just a type hint. Either replace it with something like `telegram.Message`, or delete it: `async def text_handler(message):` – Kaia Feb 10 '23 at 00:35