卡在使用 skpy 通过 Python 创建 Skype 机器人

问题描述 投票:0回答:1

我一直在尝试通过Python制作一个Skype机器人,但陷入了处理事件的困境。 我已经进行了对话并输入了无限获取事件的代码。作为回报,代码应该只对发送到对话的每条消息响应一次,直到有人发送另一条消息,依此类推。但代码运行得很疯狂,并重现了它自己发送的消息。

这是到目前为止的代码:

from skpy import Skype

user = '***'
password = '***'
group_id = '***'

class MySkype(SkypeEventLoop):

    def onEvent(self, event):
        
        if (event.type == 'NewMessage'): # and (event.userId is None):
            
            message_content = event.raw['resource']['content']
            conversation_link = event.raw['resource']['conversationLink']
            message_sender = event.raw['resource']['imdisplayname']
            ch = sk.chats.chat(group_id)
            ch.sendMsg('The code is responding to {}.\n You sent this message: {}'.format(message_sender, message_content))

sk = MySkype(user, password, autoAck = True)

sk.loop()

As you can see the code has responded to itself!

python bots skype
1个回答
0
投票

如果您向任何聊天室发送消息,此服务将接受另一条新消息,然后您再次发送新消息。

此外,您不断发送到同一个聊天室,因此它似乎一次又一次地重现相关消息。

© www.soinside.com 2019 - 2024. All rights reserved.