Add SlashCommandIgnoreAttribute for hiding enum values from slash commands - #388
Open
Zont1k wants to merge 2 commits into
Open
Add SlashCommandIgnoreAttribute for hiding enum values from slash commands#388Zont1k wants to merge 2 commits into
Zont1k wants to merge 2 commits into
Conversation
|
The documentation preview is available at https://preview.netcord.dev/388. |
KubaZ2
reviewed
Jul 28, 2026
| /// Apply this attribute to enum fields that should not be presented to users as choices. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Field)] | ||
| public class SlashCommandIgnoreAttribute : Attribute |
Member
There was a problem hiding this comment.
I think this attribute should be named SlashCommandChoiceIgnoreAttribute. SlashCommandIgnoreAttribute is misleading.
Comment on lines
+27
to
+31
| var filteredFields = fields.Where(f => f.GetCustomAttribute<SlashCommandIgnoreAttribute>() is null).ToArray(); | ||
| var count = filteredFields.Length; | ||
| var choices = new ApplicationCommandOptionChoiceProperties[count]; | ||
| for (var i = 0; i < count; i++) | ||
| choices[i] = await CreateChoiceAsync(fields[i]).ConfigureAwait(false); | ||
| choices[i] = await CreateChoiceAsync(filteredFields[i]).ConfigureAwait(false); |
Member
There was a problem hiding this comment.
Suggested change
| var filteredFields = fields.Where(f => f.GetCustomAttribute<SlashCommandIgnoreAttribute>() is null).ToArray(); | |
| var count = filteredFields.Length; | |
| var choices = new ApplicationCommandOptionChoiceProperties[count]; | |
| for (var i = 0; i < count; i++) | |
| choices[i] = await CreateChoiceAsync(fields[i]).ConfigureAwait(false); | |
| choices[i] = await CreateChoiceAsync(filteredFields[i]).ConfigureAwait(false); | |
| var ignoreAttributeType = typeof(SlashCommandIgnoreAttribute); | |
| var count = fields.Length; | |
| List<ApplicationCommandOptionChoiceProperties> choices = new(count); | |
| for (var i = 0; i < count; i++) | |
| { | |
| var field = fields[i]; | |
| if (!field.IsDefined(ignoreAttributeType)) | |
| choices.Add(await CreateChoiceAsync(field).ConfigureAwait(false)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new attribute that can be applied to enum fields to exclude them from being shown as options in slash commands.
Closes #330
Changes
Usage
Note
The project requires .NET SDK 10.0.301 for source generators which is not available in my local environment, so I was unable to run the full test suite. However, the logic is straightforward and follows the existing pattern used by .