我想让我的机器人把命令后的整个消息作为一个整体来讨论。但现在的情况是:
当我输入“!数学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
发布于 2017-02-07 01:52:48
就像克劳迪欧说的,你可以用引号把论点括起来,或者.
使用下面的余数属性,
[Command("math")]
public async Task Calculate([Remainder]string equation)
{
// Now equation will be everything after !math
// Your code here
}P.S.:在我们的Discord.Net中询问未来的不和谐服务器问题(寻找#dotnet_Discord.Net),您会更快地得到答案。
发布于 2017-02-05 16:05:07
通常,您应该将包含空格的引号参数括起来。例如:
application.exe“包含空格的一些参数”
发布于 2021-01-12 20:43:04
如果其他人不使用Discord.NET
public async Task Calc(CommandContext ctx, [RemainingText] string equation)https://stackoverflow.com/questions/42053824
复制相似问题