(python-telegram-bot)attributeError:'消息'对象没有属性'消息'
我正在尝试用“命令”作为用户回复消息的“命令”进行多回复,并收到此错误
错误
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论