【问题标题】:pyrogram send_audio throws a TypeErrorpyrogram send_audio 抛出 TypeError
【发布时间】:2021-10-07 04:09:33
【问题描述】:

我正在尝试使用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
    )
)

但是,我收到此错误:

TypeError: send_audio() missing 1 required positional argument: 'self'

【问题讨论】:

  • 您需要实例化客户端。类本身不能用于向 API 发送请求。

标签: python python-3.x pyrogram


【解决方案1】:

您需要在发送请求之前实例化该类:

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
    )
)

【讨论】:

  • 这是个坏建议。这不会启动客户端,并且会相应地出错。在客户端可以调用 API 的方法之前,它需要在上下文管理器中启动 with bot:,或者 app.start()app.stop()
猜你喜欢
  • 2011-10-03
  • 2016-11-18
  • 1970-01-01
  • 1970-01-01
  • 2018-08-28
  • 2014-10-05
  • 1970-01-01
  • 2023-03-14
  • 2021-08-05
相关资源
最近更新 更多