首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不能在python电报中发送.mp3文件

不能在python电报中发送.mp3文件
EN

Stack Overflow用户
提问于 2021-05-28 10:54:40
回答 1查看 442关注 0票数 0
代码语言:javascript
运行
复制
import logging
from telegram import Update, ForceReply
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
from telegram.files.audio import Audio


logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO
)

logger = logging.getLogger(__name__)


def start(update: Update, _: CallbackContext) -> None:
    """Send a message when the command /start is issued."""
    user = update.effective_user
    update.message.reply_markdown_v2(
        fr'Hi {user.mention_markdown_v2()}\!',
        reply_markup=ForceReply(selective=True),
    )


def help_command(update: Update, _: CallbackContext) -> None:
    """Send a message when the command /help is issued."""
    update.message.reply_text('Help!')

def sendAudio(update: Update, context: CallbackContext):
    context.bot.sendAudio(chat_id=update.message.chat_id, Audio=open("hxxxxxxxxxxxxxxxxxxx.mp3", "rb"), timeout=360)


def main() -> None:

    updater = Updater("xxxxxxxxxxxxxxxx")


    dispatcher = updater.dispatcher

    dispatcher.add_handler(CommandHandler("start", start))
    dispatcher.add_handler(CommandHandler("help", help_command))
    dispatcher.add_handler(CommandHandler("send", sendAudio))

    updater.start_polling()

    updater.idle()


if __name__ == '__main__':
    main()

这是我的代码,当我发送给/send时,它显示了这个错误

代码语言:javascript
运行
复制
2021-05-28 16:16:18,309 - telegram.ext.dispatcher - ERROR - No error handlers are registered, logging exception.
Traceback (most recent call last):
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\telegram\ext\dispatcher.py", line 447, in process_update
    handler.handle_update(update, self, check, context)
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\telegram\ext\handler.py", line 160, in handle_update
    return self.callback(update, context)
  File "e:\Projects\Python\Telegram bot\echo.py", line 28, in sendAudio
    context.bot.sendAudio(chat_id=update.message.chat_id, Audio=open("xxxxxxxxxxxxxxxxxxx.mp3", "rb"), timeout=360)
OSError: [Errno 22] Invalid argument: 'xxxxxxxxxxxxxxxxxxx.mp3'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-28 11:24:21

bot方法send_audio有一个参数,audio有一个小写的a --您用captialA来写Audio。请注意,您可以使用reply_audio快捷方式简化代码。

免责声明:我目前是python-telegram-bot的维护者

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67737575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档