如何使用 Skype4COM 在 Skype 群聊中发送消息?
Posted
技术标签:
【中文标题】如何使用 Skype4COM 在 Skype 群聊中发送消息?【英文标题】:How do I send a message in a group chat in Skype with Skype4COM? 【发布时间】:2012-05-06 04:32:06 【问题描述】:我一直在尝试用 C# 制作一个“Skype Bot”。到目前为止,我已经成功地让它在一对一的聊天中工作。我无法让它在群聊中工作。这是我的来源:
using System;
using System.Windows.Forms;
using SKYPE4COMLib;
namespace SkypeBot
public partial class Form1 : Form
private Skype skype;
private const string trigger = "!"; // Say !help
private const string nick = "Bot";
public Form1()
InitializeComponent();
private void Form1_Load(object sender, EventArgs e)
skype = new Skype();
// Use skype protocol version 7
skype.Attach(7, false);
// Listen
skype.MessageStatus += new _ISkypeEvents_MessageStatusEventHandler(skype_MessageStatus);
private void skype_MessageStatus(ChatMessage msg, TChatMessageStatus status)
if (TChatMessageStatus.cmsRead == status)
return;
if (msg.Body.IndexOf(trigger) == 0 && TChatMessageStatus.cmsReceived == status)
// Remove trigger string and make lower case
string command = msg.Body.Remove(0, trigger.Length).ToLower();
// Send processed message back to skype chat window
skype.SendMessage(msg.Sender.Handle, nick + " Says: " + ProcessCommand(command));
IChat ichat = skype.get_Chat(msg.Chat.Name);
ichat.SendMessage(msg.Sender.Handle, nick + " Says: " + ProcessCommand(command));
private string ProcessCommand(string str)
string result;
switch (str)
case "help":
result = "Sorry no help available";
break;
case "date":
result = "Current Date is: " + DateTime.Now.ToLongDateString();
break;
case "time":
result = "Current Time is: " + DateTime.Now.ToLongTimeString();
break;
case "who":
result = "I am Bot, a magical Skype robot!";
break;
case "moon":
result = "(moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) (moon) ";
break;
default:
result = "Sorry, I do not recognize your command";
break;
return result;
在它发送已处理消息的位置我收到错误“方法 'SendMessage' 没有重载需要 2 个参数”。
但是当我使用时:
skype.SendMessage(msg.Sender.Handle, nick + " Says: " +
ProcessCommand(command));
它可以完美运行,但不能用于群聊。你有什么建议吗?
【问题讨论】:
【参考方案1】:尝试使用
msg.Chat.SendMessage("your message")
改为。
最好的
【讨论】:
@user1356292,因为 Vagaus 帖子回答了您的问题,它也对您有用。你应该接受它作为答案,或者至少赞成它。没有冒犯,只是一种道德义务。以上是关于如何使用 Skype4COM 在 Skype 群聊中发送消息?的主要内容,如果未能解决你的问题,请参考以下文章
如何获取所有可用的 Microsoft bot Skype 组