Skip to main content
 首页 » 编程设计

python之Skype4Py 附加功能第二次不起作用

2025年05月04日8sky-heaven

我正在尝试编写一个会阻止某些用户的小型 Skype 机器人。

这是我的代码:

import Skype4Py 
 
skype = Skype4Py.Skype(Transport='x11') 
 
skype.Attach() 
print "Attachment status is " + str(skype.AttachmentStatus) 
... 
user._SetIsBlocked(True) 

我第一次运行此脚本时,它为我提供 1 作为 skype.AttachmentStatus,并阻止我选择的用户。 但如果我第二次运行它,它会给我 0 作为 skype.AttachmentStatus,并且不会阻止我选择的用户。

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

有人可以帮助或解释为什么会这样吗?

谢谢!

请您参考如下方法:

此错误的解决方案是将您自己的事件处理程序添加到 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 

之后每次运行它都会起作用。