使用IAsyncEnumerable错误<ireadonlycollection <iuser>&gt;在discord bot中

时间:2017-07-24 09:30:41

标签: c# discord

我有这个代码行

if (channel.GetUsersAsync().Contains(Program.kami.CurrentUser as IGuildUser))
do something;

它写了一个异常,说IAsyncEnumerable&gt;不包含contains的定义 而且我不知道该怎么做

[Command("join", RunMode=RunMode.Async), Summary("joins voice channel")]
public async Task joinvoice([Remainder, Summary("The text to echo")] string searchP="")
{

    IVoiceChannel channel = (CommandHandler.Last as IGuildUser).VoiceChannel;

    if (channel == null)
    {
        await ReplyAsync("u have to be in a channel first");
        return;

    }
    string choice = "";
    VideoSearch SearchRisolts = new VideoSearch();
    if (searchP != "")
    {
        if (searchP.Contains("https://"))
            choice = searchP;
        else
        {
            List<VideoInformation> video = SearchRisolts.SearchQuery(searchP, 1);
            await ReplyAsync("* " + video[0].Title + "\n\n* " + video[1].Title + "\n\n* " + video[2].Title);
            //choice = video[int.Parse() - 1].Url;
        }
        this.Context.Channel.GetMessagesAsync(1).First();
    }
    IAsyncEnumerable<IReadOnlyCollection<IUser>> x = channel.GetUsersAsync();
    if ((await channel.GetUsersAsync()).Contains(Program.kami.CurrentUser as IGuildUser))
    var audioClient = await channel.ConnectAsync();
    await SendAsync(audioClient,choice);

}

1 个答案:

答案 0 :(得分:2)

您需要等待GetUserAsync操作

(await channel.GetUsersAsync()).Contains(....)

确保您的方法是异步的。