(python-telegram-bot)attributeError:'消息'对象没有属性'消息'

发布于 2025-02-03 17:24:13 字数 1868 浏览 4 评论 0原文

我正在尝试用“命令”作为用户回复消息的“命令”进行多回复,并收到此错误

错误

 mesg = update.message.text.split('\n')
AttributeError: 'Message' object has no attribute 'message'

code

def _func(bot, update, multi=0):
    mesg = update.message.text.split('\n')
    message_args = mesg[0].split(' ', maxsplit=1)


    if multi > 1:
        time.sleep(4)
        nextmsg = type('nextmsg', (object, ), {'message': update.message, 'chat_id': message.chat_id, 'message_id': message.reply_to_message.message_id + 1})
        msg = message_args[0]
        if len(mesg) > 2:
            msg += '\n' + mesg[1] + '\n' + mesg[2]
        nextmsg = sendMessage(msg, bot, nextmsg)
        nextmsg.from_user.id = update.message.from_user.id
        multi -= 1
        time.sleep(4)
        _func(bot, nextmsg, multi)


def mycommand(update, context):
    _func(context.bot, update)

mycommand_handler = CommandHandler(BotCommands.MyCommandCommand, mycommand,
                                filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True)

dispatcher.add_handler(mycommand__handler)

也从另一个文件&amp中导入sendmessage函数。 sendmessage的代码

def sendMessage(text: str, bot, update: Update):
    try:
        return bot.send_message(update.message.chat_id,
                            reply_to_message_id=update.message.message_id,
                            text=text, allow_sending_without_reply=True, parse_mode='HTMl', disable_web_page_preview=True)
    except RetryAfter as r:
        LOGGER.warning(str(r))
        time.sleep(r.retry_after * 1.5)
        return sendMessage(text, bot, update)
    except Exception as e:
        LOGGER.error(str(e))

如何修复此问题并将“ mycommand”作为bot逐一作为消息作为bot,通过在用户首先标记的消息之后进行标记,以作为bot

I'm trying to multi replying with a 'command' as bot from user replied message and got this error

ERROR

 mesg = update.message.text.split('\n')
AttributeError: 'Message' object has no attribute 'message'

CODE

def _func(bot, update, multi=0):
    mesg = update.message.text.split('\n')
    message_args = mesg[0].split(' ', maxsplit=1)


    if multi > 1:
        time.sleep(4)
        nextmsg = type('nextmsg', (object, ), {'message': update.message, 'chat_id': message.chat_id, 'message_id': message.reply_to_message.message_id + 1})
        msg = message_args[0]
        if len(mesg) > 2:
            msg += '\n' + mesg[1] + '\n' + mesg[2]
        nextmsg = sendMessage(msg, bot, nextmsg)
        nextmsg.from_user.id = update.message.from_user.id
        multi -= 1
        time.sleep(4)
        _func(bot, nextmsg, multi)


def mycommand(update, context):
    _func(context.bot, update)

mycommand_handler = CommandHandler(BotCommands.MyCommandCommand, mycommand,
                                filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True)

dispatcher.add_handler(mycommand__handler)

ALSO Importing sendMessage function from another file & the CODE of the sendMessage is down

def sendMessage(text: str, bot, update: Update):
    try:
        return bot.send_message(update.message.chat_id,
                            reply_to_message_id=update.message.message_id,
                            text=text, allow_sending_without_reply=True, parse_mode='HTMl', disable_web_page_preview=True)
    except RetryAfter as r:
        LOGGER.warning(str(r))
        time.sleep(r.retry_after * 1.5)
        return sendMessage(text, bot, update)
    except Exception as e:
        LOGGER.error(str(e))

How to fix this and send "mycommand" as bot one by one as message to bot by tagging after user first tagged message

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文