Search Results for

    Show / Hide Table of Contents

    Hello World

    0.开始之前

    需要下载的内容:

    1. 酷Q
    2. cqhttp插件
    3. dotnet core

    1.搭建一个酷Q实例并开启事件上报

    请参考
    酷Q官网
    cqhttp插件文档

    2.创建一个 .NET console项目

    在https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial#install获取.NET工具包
    在任意目录下创建项目文件夹,并在cmd中执行

    dotnet new console -o [给项目起的名字]
    

    3.添加nuget包

    在项目目录下执行

    dotnet add package cqhttp.Cyan
    dotnet restore
    

    4.掌握一定的C#语言基础,并在Program.cs中编写bot逻辑

    using cqhttp.Cyan;
    using cqhttp.Cyan.Clients;
    namespace YourNS {
        class Program {
            static void Main(string[] args) {
                CQApiClient client = CQHTTPClient (
                    access_url: "http://domain:port/path",
                    access_token: "your_token",
                    listen_port: 8080,
                    secret: "your_secret"
                );
                Console.WriteLine(
                    $"QQ:{client.self_id},昵称:{client.self_nick}"
                );
                //client构造后会发送一条get_login_info请求,则可以通过
                //判断是否成功获取登陆的账号的QQ与昵称判断API是否可访问
                client.OnEvent += (client, e) => {
                    //process (CQEvent e)
                    return new CQEmptyResponse ();
                };
                client.SendTextAsync(
                    MessageType.private_,
                    12345678,
                    "一条文字消息"
                );
                Console.ReadLine();
            }
        }
    }
    

    在Examples下有更多示例

    Next Step

    消息的接收与处理

    • Improve this Doc
    ☀
    ☾