public static DiscordCommand AddCommand(string commandName, Func <DiscordCommandArguments, Task> commandAction) { if (commandName == null || commandName.Length == 0 || commandAction == null) { return(null); } DiscordCommand cmd = new DiscordCommand(commandName, commandAction); commands.Add(cmd); return(cmd); }
public static async Task AttemptToRunCommand(MessageEventArgs e) { string commandLine = e.Message.Text.Substring(1); List <string> cmdParts = Regex.Matches(commandLine, @"[\""].+?[\""]|[^ \n]+") .Cast <Match>() .Select(m => m.Value) .ToList(); DiscordCommand cmd = commands.Find(c => c.HasCommandName(cmdParts[0])); if (cmd != null) { Console.WriteLine($"{e.Message.User.Name} ran command '{cmdParts[0]}'"); await cmd.Execute(e, cmdParts); return; } Console.WriteLine($"{e.Message.User.Name} attempted to run command '{cmdParts[0]}' (Command not found)"); await e.Channel.SendMessage(e.Message.User.Mention + " - Sorry, but that command was not found"); }