我试图制作一个 Skype 机器人,它会在发送某个关键字时自动发回一条消息。它似乎在 MVS 中运行良好,但是当我实际运行它时,我收到此错误未处理的异常已在您的应用程序中发生;
************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {830690FC-BF2F-47A6-AC2D-330BCB402664} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
at SkypeBing.Form1.Form1_Load(Object sender, EventArgs e) in c:\Users\Harry\Desktop\SkypeBot\Form1.cs:line 21
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
这是应用程序的代码;
using System;
using System.Windows.Forms;
using SKYPE4COMLib;
namespace SkypeBing
{
public partial class Form1 : Form
{
private Skype skype;
private const string trigger = "!"; // Say !help
private const string nick = "HM-STORE 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)
{
// Proceed only if the incoming message is a trigger
if (msg.Body.IndexOf(trigger) >= 0)
{
// 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));
}
}
private string ProcessCommand(string str)
{
string result;
switch (str)
{
case "hello":
result = "Hello! Type !key if you are intrested in a key";
break;
case "key":
result = "To buy a key go to http://www.mywebsite.org! if you enjoyed shopping at us please leave a vouch on our post!";
break;
case "date":
result = "Current Date is: " + DateTime.Now.ToLongDateString();
break;
case "time":
result = "Current Time is: " + DateTime.Now.ToLongTimeString();
break;
case "who":
result = "This is the HM skype bot!";
break;
default:
result = "To buy a key or anything else go to http://www.hmstore.zzl.org!";
break;
}
return result;
}
}
}