功能菜单5向用户返回一条消息。我想同时用户调用此函数,它调用另一个类似的函数,它将消息发送给另一个人。 这是代码:
def menu5(self, message=None, match=None, to=None):
# Retransfer the requester's phone
number = message.getFrom()
# Cut after the @
number = number.split('@')
# Separate only the number
number = number[0]
# Delete the 55
number = number[2:13]
# Person who will receive the message
toSend = '5527999999999@s.whatsapp.net'
# Function call to be triggered
self.operator(msg=number, op=toSend)
return textMessageProtocolEntity(txtMenu5, to=message.getFrom())
def operator(self, to=None, msg=None, op=None):
return TextMessageProtocolEntity(msg, to=op)
答案 0 :(得分:0)
如果你想要某个函数的返回值,你需要明确地存储它:
def menu5(self, message=None, match=None, to=None):
# ...
# Function call to be triggered
txtmsg = self.operator(msg=number, op=toSend)
return TextMessageProtocolEntity(txtMenu5, to=message.getFrom()), txtmsg
函数menu5
现在返回一个包含两个TextMessageProtocolEntity
的双元素元组。请注意,您的原始代码始终按预期调用self.operator
- 它只是没有对返回值执行任何操作。