【问题标题】:getting message in a command from the discord chat从不和谐聊天的命令中获取消息
【发布时间】:2017-12-31 21:02:39
【问题描述】:

我有这行需要接收来自不和谐文本频道的消息。

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);

}

【问题讨论】:

    标签: c# discord discord.net


    【解决方案1】:

    包含这个函数的类应该派生自BaseModule&lt;ICommandContext&gt;

    BaseModule 包含上下文,其中包含您正在寻找的消息。

    Context.Message.Content
    

    【讨论】:

      猜你喜欢
      • 2019-04-09
      • 1970-01-01
      • 2018-12-15
      • 2021-10-04
      • 1970-01-01
      • 2021-08-26
      • 2020-09-09
      • 2021-12-12
      • 2019-04-14
      相关资源
      最近更新 更多