Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions DSharpPlus.SlashCommands/SlashCommandsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ private void RegisterCommands(IEnumerable<Type> types, ulong? guildId)
//Gets the paramaters and accounts for InteractionContext
var parameters = submethod.GetParameters();
if (parameters?.Length is null or 0 || !ReferenceEquals(parameters.First().ParameterType, typeof(InteractionContext)))
throw new ArgumentException($"The first argument must be an InteractionContext!");
throw new ArgumentException($"The given command method {submethod.Name} is invalid: The first argument must be an InteractionContext!");
parameters = parameters.Skip(1).ToArray();

//Check if the ReturnType can be safely casted to a Task later on execution
if (!typeof(Task).IsAssignableFrom(submethod.ReturnType))
throw new InvalidOperationException("The method has to return a Task or Task<> value");
throw new InvalidOperationException($"The given command method {submethod.Name} is invalid: The method has to return a Task or Task<> value");

var options = await this.ParseParameters(parameters, guildId);

Expand Down Expand Up @@ -242,7 +242,12 @@ private void RegisterCommands(IEnumerable<Type> types, ulong? guildId)
var commatt = subsubmethod.GetCustomAttribute<SlashCommandAttribute>();
var parameters = subsubmethod.GetParameters();
if (parameters?.Length is null or 0 || !ReferenceEquals(parameters.First().ParameterType, typeof(InteractionContext)))
throw new ArgumentException($"The first argument must be an InteractionContext!");
throw new ArgumentException($"The given command method {subsubmethod.Name} is invalid: The first argument must be an InteractionContext!");

//Check if the ReturnType can be safely casted to a Task later on execution
if (!typeof(Task).IsAssignableFrom(subsubmethod.ReturnType))
throw new InvalidOperationException($"The given command method {subsubmethod.Name} is invalid: The method has to return a Task or Task<> value");

parameters = parameters.Skip(1).ToArray();
suboptions = suboptions.Concat(await this.ParseParameters(parameters, guildId)).ToList();

Expand Down Expand Up @@ -297,7 +302,7 @@ private void RegisterCommands(IEnumerable<Type> types, ulong? guildId)

var parameters = method.GetParameters();
if (parameters?.Length is null or 0 || !ReferenceEquals(parameters.FirstOrDefault()?.ParameterType, typeof(InteractionContext)))
throw new ArgumentException($"The first argument must be an InteractionContext!");
throw new ArgumentException($"The given command method {method.Name} is invalid: The first argument must be an InteractionContext!");
parameters = parameters.Skip(1).ToArray();
var options = await this.ParseParameters(parameters, guildId);

Expand Down Expand Up @@ -335,9 +340,9 @@ void AddContextMenus(IEnumerable<MethodInfo> contextMethods)

var parameters = contextMethod.GetParameters();
if (parameters?.Length is null or 0 || !ReferenceEquals(parameters.FirstOrDefault()?.ParameterType, typeof(ContextMenuContext)))
throw new ArgumentException($"The first argument must be a ContextMenuContext!");
throw new ArgumentException($"The given command method {contextMethod.Name} is invalid: The first argument must be a ContextMenuContext!");
if (parameters.Length > 1)
throw new ArgumentException($"A context menu cannot have parameters!");
throw new ArgumentException($"The given command method {contextMethod.Name} is invalid: A context menu cannot have parameters!");

contextMenuCommands.Add(new ContextMenuCommand { Method = contextMethod, Name = contextAttribute.Name });

Expand Down