F
F
From Prog2021-08-15 23:12:31
Python
From Prog, 2021-08-15 23:12:31

How to specify the name of the audio to be sent to the TG bot (aiogram)?

*Хэндлер*
*Функция*:
    await mybot.send_message(message.chat.id, 'Получаю аудио...')
    rand_1_to_3 = random.randint(0, 2)
    if rand_1_to_3 == 0:
      await mybot.send_audio(message.chat.id, open('settings/first_relax.mp3', 'rb', audioname='The Chords — Sh-boom'))
    elif rand_1_to_3 == 1:
      await mybot.send_audio(message.chat.id, open('settings/second_relax.mp3', 'rb', audioname='J.S. Bach – Orchestral Suite No. 3 in D Major, BWV 1068 - II. Air'))
    elif rand_1_to_3 == 2:
      await mybot.send_audio(message.chat.id, open('settings/third_relax.mp3', 'rb', audioname='Erik Satie – Gymnopédie No.3'))

It doesn’t work like that, and if you remove the filename argument from open(), it doesn’t work either, how can you do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
KrimsN, 2021-08-16
@FromProg

In order to understand how the function works, I advise you to look at the documentation of the library from which this function is.
In this case, you need to pass to the send_audio method not a file descriptor, but an object from the aiogram FSInputFile framework

M
Mikhail Krostelev, 2021-08-16
@twistfire92

A very strange question, the answer to which lies on the surface .
If such things cause difficulties, I advise you to roll back a little in learning programming in general. Read books, do simpler tasks. For some reason, everyone immediately climbs into bots, although they have a mediocre idea of ​​\u200b\u200bbasic concepts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question