2012-10-23 55 views
2

我正在尝试编写一个会阻止某些用户的小型Skype机器人。Skype4Py附加功能不能正常工作第二次

这是我的代码:

import Skype4Py 

skype = Skype4Py.Skype(Transport='x11') 

skype.Attach() 
print "Attachment status is " + str(skype.AttachmentStatus) 
... 
user._SetIsBlocked(True) 

我第一次运行该脚本,它给了我为skype.AttachmentStatus,并阻止我选择了用户。 但是如果我第二次运行它,它会给我为skype.AttachmentStatus,并且不会阻止我选择的用户。

如果我等一段时间(大约5分钟)然后尝试再次运行脚本,它开始工作。但只有一次。我必须再等五分钟才能再次运行它。

有人可以帮助或解释为什么会发生这种情况吗?

谢谢!

回答

1

解决这个错误是自己的事件处理程序添加到skype.OnAttachmentStatus

例子:

# Attachment status handler 
def OnAttach(status): 
    print 'API attachment status: ' + skype.Convert.AttachmentStatusToText(status) 
    if status == Skype4Py.apiAttachAvailable: 
    skype.Attach() 

    if status == Skype4Py.apiAttachSuccess: 
    print '*************************************************' 

... 

# Creating Skype object, assigning handler functions and attaching to Skype 
skype = Skype4Py.Skype(Transport='x11') 
skype.OnAttachmentStatus = OnAttach 
skype.OnMessageStatus = OnMessageStatus 

之后,它会工作每次运行它的时候。

+0

你在OSX上试过这个,Windows 10没有工作 – YumYumYum