C# + Discord.NET - 带字符串的命令?

C# + Discord.NET - Command with string?

所以我想创建一个命令,用户在命令中输入其他内容,然后由该命令定义一个字符串。该字符串稍后用于将用户重定向到网站。

含义:

//The string is defined here by user (string = what user typed in after "command") (how?)
commands.CreateCommand("command", string add_link)

            .Do(async (e) =>
            {
//String is added to website.
                await e.Channel.SendMessage("www.website.com/" + add_link);
            });

这可能吗?

非常简单,您只需添加对 .Parameter() 的调用以定义它,然后使用 GetArgs() 检索它。看这个例子:

 cmd.CreateCommand("linkit")                
 .Parameter("url", ParameterType.Unparsed)
 .Do(async e =>
 {
     string msg = e.GetArg("url");                        
     await e.Channel.SendMessage("the text is: "+msg);
 });

这将像这样使用(假设您的机器人的密钥是“!”):

[fhl] !linkit foobar
[bot] the text is: foobar

改编自此示例机器人的示例:https://github.com/RogueException/DiscordBot