-
-
Notifications
You must be signed in to change notification settings - Fork 745
Open
Labels
Description
Check The Docs
- I double checked the docs and couldn't find any useful information.
Verify Issue Source
- I verified the issue was caused by Discord.Net.
Check your intents
- I double checked that I have the required intents.
Description
Unquantified wildcards can no longer be optional, before a component interaction with [ComponentInteraction("foo:*")]
would be able to capture empty strings, such as the id foo:
.
Now it needs to have at least one character for it to work. i.e. foo:bar
.
A workaround for this is using a quantified count of 0 or more, i.e. [ComponentInteraction("foo:{0,}")]
Version
3.18.0
Working Version
Before 3.9.0
Logs
N/A
Sample
using System.Threading.Tasks;
using Discord;
using Discord.Interactions;
using Discord.WebSocket;
// This module demonstrates the wildcard matching behavior for component interactions.
public class SampleModule : InteractionModuleBase<SocketInteractionContext>
{
// This command creates a select menu with a custom ID that has an empty segment.
// The custom ID will be "test-menu:123:", where the part after the last colon is empty.
[SlashCommand("test", "Sends a test menu.")]
public async Task SendTestMenu()
{
var menu = new SelectMenuBuilder()
.WithCustomId("test-menu:123:") // Note the empty string after the last colon.
.WithPlaceholder("Select an option")
.AddOption("Option 1", "opt1");
var components = new ComponentBuilder().WithSelectMenu(menu);
await RespondAsync("This menu demonstrates the wildcard issue.", components: components.Build());
}
/*
* This handler will NOT be triggered.
* The unquantified wildcard `*` for the `emptySegment` parameter requires at least one character.
* Since the custom ID is "test-menu:123:", the last segment is empty, and this pattern will not match.
*/
[ComponentInteraction("test-menu:*:*")]
public async Task HandleMenu_Broken(string userId, string emptySegment, string[] selections)
{
// This code will not be reached.
await RespondAsync($"Broken handler triggered with user ID: {userId} and empty segment: '{emptySegment}'.");
}
/*
* This is the corrected handler.
* The quantified wildcard `{0,}` allows the `emptySegment` to match zero or more characters.
* This pattern will correctly match the custom ID "test-menu:123:".
*/
[ComponentInteraction("test-menu:*:{0,}")]
public async Task HandleMenu_Fixed(string userId, string emptySegment, string[] selections)
{
// This code will be executed.
await RespondAsync($"Fixed handler triggered. User ID: {userId}, Empty Segment: '{emptySegment}', Selection: {selections[0]}");
}
}
Packages
Discord.NET 3.18.0
Environment
- OS: Windows
- Arch: x64
- SDK: .NET SDK 9.0