Skype4Py:获取发送消息对象的句柄
我正在用 skype4py 做一个小机器人,这个机器人是连接在我自己的 Skype 客户端上的。我希望这个机器人能够接受我自己或者我聊天的人的输入,并且把回复发回到输入来源的聊天窗口。
为此,我使用 sendMessage(msgtext, handle_of_person_im_chatting_with) 这个方法。
当我收到聊天对象的指令时,这个过程相对简单,因为收到的事件中有一个 'fromHandle' 属性,里面包含了对方的用户名,这样我就可以直接把消息发给那个用户名。但是我就是搞不懂,如何从发送事件中获取到这个用户的用户名。
1 个回答
0
把这个放在导入语句后面最上面
def commands(Message, Status):
if Status == 'RECEIVED' or (Status == 'SENT'):
if Message.Body.startswith(".help"):
cmd_help(Message)
然后为了在使用 .help 时有输出,放这个
def cmd_commandhere(Message):
Message.Chat.SendMessage("Hello, " + Message.Sender.Handle)
print "commandhere command received from: " + Message.Sender.Handle
最后在底部放这个
skype = Skype4Py.Skype()
client = Skype4Py.client.Client(skype)
skype.OnMessageStatus = commands
Skype.Attach()
while True:
raw_input('')