diff --git a/src/Discord.Net.Interactions/Attributes/AutocompleteAttribute.cs b/src/Discord.Net.Interactions/Attributes/AutocompleteAttribute.cs index c8a3428d..fc84d58f 100644 --- a/src/Discord.Net.Interactions/Attributes/AutocompleteAttribute.cs +++ b/src/Discord.Net.Interactions/Attributes/AutocompleteAttribute.cs @@ -1,36 +1,46 @@ using System; -namespace Discord.Interactions +namespace Discord.Interactions; + +/// +/// Set the to . +/// +[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] +public class AutocompleteAttribute : Attribute { /// - /// Set the to . + /// Type of the . /// - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] - public class AutocompleteAttribute : Attribute + public Type AutocompleteHandlerType { get; } + + /// + /// Set the to and define a to handle + /// Autocomplete interactions targeting the parameter this is applied to. + /// + /// + /// must be set to to use this constructor. + /// + public AutocompleteAttribute(Type autocompleteHandlerType) { - /// - /// Type of the . - /// - public Type AutocompleteHandlerType { get; } + if (!typeof(IAutocompleteHandler).IsAssignableFrom(autocompleteHandlerType)) + throw new InvalidOperationException($"{autocompleteHandlerType.FullName} isn't a valid {nameof(IAutocompleteHandler)} type"); - /// - /// Set the to and define a to handle - /// Autocomplete interactions targeting the parameter this is applied to. - /// - /// - /// must be set to to use this constructor. - /// - public AutocompleteAttribute(Type autocompleteHandlerType) - { - if (!typeof(IAutocompleteHandler).IsAssignableFrom(autocompleteHandlerType)) - throw new InvalidOperationException($"{autocompleteHandlerType.FullName} isn't a valid {nameof(IAutocompleteHandler)} type"); - - AutocompleteHandlerType = autocompleteHandlerType; - } - - /// - /// Set the to without specifying a . - /// - public AutocompleteAttribute() { } + AutocompleteHandlerType = autocompleteHandlerType; } + + /// + /// Set the to without specifying a . + /// + public AutocompleteAttribute() { } +} + +/// +/// Set the to . +/// +/// Type of the that will be used to handle Autocomplete interactions targeting the parameter. +[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] +public class AutocompleteAttribute : AutocompleteAttribute + where T : class, IAutocompleteHandler +{ + public AutocompleteAttribute() : base(typeof(T)) { } } diff --git a/src/Discord.Net.Interactions/Discord.Net.Interactions.csproj b/src/Discord.Net.Interactions/Discord.Net.Interactions.csproj index a3ac3d50..653f746b 100644 --- a/src/Discord.Net.Interactions/Discord.Net.Interactions.csproj +++ b/src/Discord.Net.Interactions/Discord.Net.Interactions.csproj @@ -3,12 +3,14 @@ net6.0;net5.0;net461;netstandard2.0;netstandard2.1 + preview net6.0;net5.0;netstandard2.0;netstandard2.1 Discord.Interactions Discord.Net.Interactions A Discord.Net extension adding support for Application Commands. 5 True + true