如何在 Python 中使用 Skype4Py 向群组对话发送消息 [英] How can I send a message to a group conversation with Skype4Py in Python
问题描述
我一直在尝试让我的脚本使用 Skype4Py 库向 Skype 中的群组对话发送消息,我目前能够向特定用户发送消息的唯一方法.
导入Skype4PySkype = Skype4Py.Skype()Skype.Attach()Skype.SendMessage('namehere','testmessage')
有谁知道如何更改我的代码以向群组对话发送消息?
下面的小脚本应该可以工作.(假设您已经打开群聊)
def sendGroupChatMessage():"""发送群聊消息."""将 Skype4Py 导入为 SkypeskypeClient = skype.Skype()skypeClient.Attach()对于 skypeClient.ActiveChats 中的元素:如果 len(elem.Members) >2:elem.SendMessage("SomeMessageHere")
我基本上是导入所有当前聊天记录,检查成员数量并相应地发送消息.在不同的组内也应该很容易检查.
要获得句柄,请将您的函数更改为此.
def sendGroupChatMessage():"""发送群聊消息."""将 Skype4Py 导入为 SkypeskypeClient = skype.Skype()skypeClient.Attach()对于 skypeClient.ActiveChats 中的元素:如果 len(elem.Members) >2:对于 elem.Members 中的朋友:打印friend.Handleelem.SendMessage("SomeMessageHere")
如果您可以为聊天添加书签,那么您只需这样做.
<预><代码>>>>groupTopic = '在此处插入主题'>>>在 skypeClient.BookmarkedChats 中聊天:如果 chat.Topic == groupTopic:chat.SendMessage("在这里发送消息")这是应该独立的最终代码.
def sendGroupChatMessage(topic=""):"""发送群聊消息."""将 Skype4Py 导入为 SkypeskypeClient = skype.Skype()skypeClient.Attach()messageSent = 假对于 skypeClient.ActiveChats 中的元素:如果 len(elem._GetMembers()) >2 和 elem.Topic == 主题:elem.SendMessage("SomeMessageHere")messageSent = 真如果不是 messageSent:在 skypeClient.BookmarkedChats 中聊天:如果 chat.Topic == 主题:chat.SendMessage("SomeMessageHere")messageSent = 真返回消息已发送
I've been trying to get my script to send a message to a group conversation in Skype using the Skype4Py library, the only way I am currently able to send messages is to specific users.
import Skype4Py
Skype = Skype4Py.Skype()
Skype.Attach()
Skype.SendMessage('namehere','testmessage')
Does anyone know how I can change my code to send a message to a group conversation?
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
这篇关于如何在 Python 中使用 Skype4Py 向群组对话发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!