将整个消息字符串作为参数

Taking whole message string as an argument

我希望我的机器人将命令后的整个消息作为一个完整的参数。但现在是这样的情况:
当我输入“!math 1 + 3”时,它只需要“1”作为参数。我希望机器人将整个字符串“1 + 3”作为参数。

这是我的代码:

    [Command("math")]
            public async Task Calculate(string equation)
            {
                string result = new DataTable().Compute(equation, null).ToString();
//Basically to calculate from the string to find the result
                if (result == "NaN")
                {
                    await Context.Channel.SendMessageAsync("Infinity or undefined");
                }
                else
                {
                    await Context.Channel.SendMessageAsync(result);
                }
            }

我目前正在使用 Discord.NET v1.0

通常您应该将包含空格的参数括在引号中。例如:

application.exe "some argument that contains spaces"

如 Claudiu 所说,您可以将参数括在引号中,或者...

像这样使用 [Remainder] 属性,

[Command("math")]
public async Task Calculate([Remainder]string equation)
{
    // Now equation will be everything after !math
    // Your code here
}

P.S.: 在我们的 Discord Server 中提出未来 Discord.Net 的问题(查找 #dotnet_discord-net),您会更快得到答案。

如果其他人没有使用 Discord.NET

public async Task Calc(CommandContext ctx, [RemainingText] string equation)