Discord c# - Check number of parameters in a command

1.1k views Asked by At

With my discord bot in c#, i tried to send an help message of command if there is 0 paramater sent. Command: !onserver >> Send help message

Thank you for your help.

commands.CreateCommand("onserver")
 .Parameter("server", ParameterType.Required)
 .Hide()
 .Do(async (e) =>
 {
    int server = Convert.ToInt32(e.GetArg("server"));
    if (e.GetArg("server").Length == 0) //Show command help
     {
         await e.Channel.SendMessage("Help message blablabla");
     } 
     if (server > 0)
     {
         await e.Channel.SendMessage($"Utilisateur lanceur: {e.Message.User}");
         await e.Channel.SendMessage($"Serveur choisi: {server}");
     }
 });
1

There are 1 answers

0
Plohej On

try: int server = Convert.ToInt32(e.Args[0]);