Example #1
0
        private async Task SendMissingParametersErrorResponse(Command command, string commandName, ISocketMessageChannel channel)
        {
            EmbedResponse.Builder builder = new EmbedResponse.Builder(EmbedResponseTemplate.Error);
            builder.AddMessage("Not enough parameters.", "You are missing some parameters.");
            ParameterInfo[] parameters = command.method.GetParameters();
            string          usage      = $"{TamaChan.Instance.botSettings.commandPrefix}{commandName}";

            for (int i = 0; i < parameters.Length; i++)
            {
                ParameterInfo pi = parameters[i];

                if (!pi.ParameterType.IsAssignableFrom(typeof(MessageContext)))
                {
                    ParameterInfo nextParameter = (i < parameters.Length - 1) ? parameters[i + 1] : null;
                    if (pi.IsOptionalParameter(nextParameter))
                    {
                        usage += $" ({pi.Name})";
                    }
                    else
                    {
                        usage += $" {pi.Name}";
                    }
                }
            }
            builder.AddMessage("Usage:", usage);
            builder.SetFooter($"Example: {command.Example}");

            await responseHandler.Respond(builder.Build(), channel);
        }