1

I am trying to send audio using pyrogram:

from pyrogram import Client as bot


await bot.send_audio(
    chat_id=from_uid,
    audio=path+'/'+file,
    caption=f"`{file}`",
    duration=duration,
    reply_to_message_id=user_msg.message.reply_to_message.message_id,
    # performer=response_json["uploader"],
    # title=response_json["title"],
    reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton('⚙ Join Updates Channel ⚙', url='https://telegram.me/FayasNoushad')]]),
    progress=progress_for_pyrogram,
    progress_args=(
        Translation.UPLOAD_START,
        user_msg,
        start_time
    )
)

However, I get this error:

TypeError: send_audio() missing 1 required positional argument: 'self'
Anonymous
  • 738
  • 4
  • 14
  • 36

1 Answers1

1

You need to instantiate the class before sending requests:

from pyrogram import Client


bot = Client('session_name')
await bot.send_audio(
    chat_id=from_uid,
    audio=path+'/'+file,
    caption=f"`{file}`",
    duration=duration,
    reply_to_message_id=user_msg.message.reply_to_message.message_id,
    # performer=response_json["uploader"],
    # title=response_json["title"],
    reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton('⚙ Join Updates Channel ⚙', url='https://telegram.me/FayasNoushad')]]),
    progress=progress_for_pyrogram,
    progress_args=(
        Translation.UPLOAD_START,
        user_msg,
        start_time
    )
)
Anonymous
  • 738
  • 4
  • 14
  • 36
  • This is bad advice. This does not start the client and will err accordingly. Before a client can call methods to the API, it needs to be started either `with bot:` in a context manager, or `app.start()` and `app.stop()`. – ColinShark Aug 12 '21 at 09:17