【问题标题】:C# + Discord.NET - Command with string?C# + Discord.NET - 带字符串的命令?
【发布时间】:2017-11-11 14:26:33
【问题描述】:

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

意思:

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

这可能吗?

【问题讨论】:

  • 那么,用户输入“command thingamabob”,而您想将“thingamabob”作为字符串单独获取?
  • @JamesCurran 是的,我正是想要那个。

标签: c# string command message discord.net


【解决方案1】:

这非常简单,您只需添加对 .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

【讨论】:

  • @ThePebbleStealer 没问题。我在答案中添加了示例机器人的链接,它演示了大部分 Discord.Net API
猜你喜欢
  • 2018-04-12
  • 1970-01-01
  • 2019-05-13
  • 1970-01-01
  • 1970-01-01
  • 2020-11-21
  • 1970-01-01
  • 1970-01-01
  • 2021-07-07
相关资源
最近更新 更多