从不和谐的聊天中获取命令中的消息

getting message in a command from the discord chat

我有这条线路需要从 discord 文本频道接收消息。

choice = video[int.Parse(CommandHandler.message .Content)-1].Url;

我尝试了很多方法,包括在 api 中搜索,但我没有任何线索。

这是命令

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

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

    if (voicechannel == 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("1) " + video[0].Title + "\n\n2) " + video[1].Title + "\n\n3) " + video[2].Title);

            choice = video[int.Parse(CommandHandler.message .Content)-1].Url;//here i need to recive a message from the chat
        }
    }

    if (voicechannel != Program.voicechannel)
    {
        Program.audioClient = await voicechannel.ConnectAsync();
        Program.voicechannel = voicechannel;

    }
    if (Program.audioClient!=null)
        await SendAsync(Program.audioClient, choice);

}

包含此函数的 class 应派生自 BaseModule<ICommandContext>

BaseModule 包含上下文,其中包含您要查找的消息。

Context.Message.Content