Reputation: 4056
I want my bot to take the whole message after the command as a whole argument. But right now this is the situation :
When I type "!math 1 + 3" it only takes "1" as an argument. I want the bot to takes the whole string of "1 + 3" as an argument instead.
This is my code :
[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);
}
}
I am currently using Discord.NET v1.0
Upvotes: 1
Views: 2186
Reputation: 3
If anyone else not using Discord.NET
public async Task Calc(CommandContext ctx, [RemainingText] string equation)
Upvotes: 0
Reputation: 381
Like Claudiu said, you can enclose the arguments in quotes, or...
Use the [Remainder] attribute like so,
[Command("math")]
public async Task Calculate([Remainder]string equation)
{
// Now equation will be everything after !math
// Your code here
}
P.S.: Ask future Discord.Net questions in our Discord Server (look for #dotnet_discord-net), you'll get your answer much quicker.
Upvotes: 3
Reputation: 194
Typically you should enclose in quotes arguments that contain spaces. For example:
application.exe "some argument that contains spaces"
Upvotes: 1