【问题标题】:Skype BOT C# Not Running CorrectlySkype BOT C# 未正确运行
【发布时间】:2015-06-01 07:40:29
【问题描述】:

我正在用 C# 制作一个 Skype 机器人,但我遇到了问题。它不是读取我自己的命令,而是其他人收到的命令。

当我添加诸如“!解决(用户名)”之类的内容时,它会使代码全部被错误地破坏,我的意思是它只是在我启动它时使工具崩溃。

有人可以看看有没有什么大问题。

private Skype skype;
    private const string trigger = "!";
    private const string nick = "The OG Bot";

还有这个

private string ProcessCommand(string str)
    {
        string result;
        switch (str)
        {
            case "resolve":
                result = "Currently Not Working Will Fix Soon.";
                break;
            case "help":
                result = "Here are some commands you can run. \n !resolve \n !date \n !time \n !who \n !swag \n !ip";
                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 API was created by TehMerkMods";
                break;
            case "ip":
                result = new WebClient().DownloadString("http://icanhazip.com");
                break;
            case "swag":
                result = "(mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) ";
                break;
            default:
                result = "Sorry, I do not recognize your command";
                break;
        }

        return result;
    }

最后一点

private void skype_MessageStatus(ChatMessage msg, TChatMessageStatus status)
    {
        if (TChatMessageStatus.cmsRead == status)
        {
            return;
        }

        if (msg.Body.IndexOf(trigger) == 0 && TChatMessageStatus.cmsReceived == status)
        {
            string command = msg.Body.Remove(0, trigger.Length).ToLower();
            skype.SendMessage(msg.Sender.Handle, nick + " : " + ProcessCommand(command));
        }
    }

【问题讨论】:

  • “使代码全部出错”是什么意思?请描述您期望的行为和您看到的行为。我们需要详细信息。
  • @Amy 好吧,基本上它不会抓取功能,之后它只会给我一个构建错误,基本上它无法读取我自己的命令,但读取其他用户发送的命令就好了
  • 能否请您发布崩溃时收到的错误信息?
  • 您遇到构建错误? 什么构建错误?当我说我们需要详细信息时,我的意思是您需要向我们提供详细信息。 要具体,不要含糊。

标签: c# bots skype skype4com


【解决方案1】:

您在最后一段代码中有一个 if 语句,它只查找 TChatMessageStatus.cmsReceived。当您发送消息时,此声明永远不会成立,因为您没有收到自己的消息。

至于程序崩溃……你需要提供更多信息。

【讨论】:

    【解决方案2】:

    你只是得到'received',你还需要得到'send'

    例子:

    if (TChatMessageStatus.cmsReceived Or Status = TChatMessageStatus.cmsSent)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-03
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多