How can I send a message to a group conversation with Skype4Py in Python

家住魔仙堡 提交于 2019-12-02 21:25:22

The following little script should work. (Assuming you already have a group chat open)

def sendGroupChatMessage():
    """
    Send Group Chat Messages.
    """
    import Skype4Py as skype
    skypeClient = skype.Skype()
    skypeClient.Attach()
    for elem in skypeClient.ActiveChats:
        if len(elem.Members) > 2:
            elem.SendMessage("SomeMessageHere")

I'm basically importing all the current chats, checking the number of members and sending a message accordingly. It should be easy to check within various groups too.

To get the handles too, change your function to this.

def sendGroupChatMessage():
    """
    Send Group Chat Messages.
    """
    import Skype4Py as skype
    skypeClient = skype.Skype()
    skypeClient.Attach()
    for elem in skypeClient.ActiveChats:
        if len(elem.Members) > 2:
            for friend in elem.Members:
                  print friend.Handle
            elem.SendMessage("SomeMessageHere")

If you can bookmark your chat, you just have to do this, then.

>>> groupTopic = 'Insert a Topic Here'
>>> for chat in skypeClient.BookmarkedChats:
        if chat.Topic == groupTopic:
            chat.SendMessage("Send a Message Here")

This is the final code that should be standalone.

def sendGroupChatMessage(topic=""):
    """
    Send Group Chat Messages.
    """
    import Skype4Py as skype
    skypeClient = skype.Skype()
    skypeClient.Attach()
    messageSent = False
    for elem in skypeClient.ActiveChats:
        if len(elem._GetMembers()) > 2 and elem.Topic == topic:
            elem.SendMessage("SomeMessageHere")
            messageSent = True

    if not messageSent:
        for chat in skypeClient.BookmarkedChats:
            if chat.Topic == topic:
                chat.SendMessage("SomeMessageHere")
                messageSent = True

    return messageSent
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!