首页 > 解决方案 > 如何在 Discord 上正确使用 unirest-net

问题描述

我想ReplyAsync为一首特定的歌曲添加歌词,所以我使用了 unirest-net api。这是我使用命令的方式:

/// <summary> The lyric generating task </summary>
/// <returns> The <see cref="Task"/> </returns>
[Command("lyric")]
public async Task LyricTask()
{
    Task<HttpResponse<string>> response = Unirest.get("https://musixmatchcom-musixmatch.p.mashape.com/wsr/1.1/matcher.lyrics.get?q_artist=imagine+dragons&q_track=Battle+cry")
        .header("X-Mashape-Key", "secret_key")
        .header("Accept", "application/json")
        .asJsonAsync<string>();

    await this.ReplyAsync(response.ToString());
}

但我总是得到输出System.Threading.Tasks.Task1[unirest_net.http.HttpResponse1[System.String]]。我做错了什么,我该如何让它发挥作用?

标签: c#.netdiscordunirestdiscord.net

解决方案


我以前没有使用HttpResponse过,但是在查看文档之后,我认为您需要调用Flush()而不是ToString().

Flush()文档中:

将所有当前缓冲的输出发送到客户端。

编辑:您必须Flush()从对象的Result属性中Task<HttpResult>调用:

await this.ReplyAsync(response.Result.Flush());


推荐阅读