I have a slash command that returns a select menu containing available commands that the user can run. However, upon select menu execution, I was getting a The server responded with error 40060: Interaction has already been acknowledged. exception. After debugging, I believe this to be a symptom of a second attempt of UpdateAsync due to the HandleHelpMenu getting invoked twice. I tried to ensure only one event was being fired by stripping it prior as a stopgap, but it is still executing twice.
Thoughts ?
P.S. This could just be 5am brain being stupid, so hoping for a second pair of eyes.
public class SlashHelp : InteractionModuleBase<SocketInteractionContext> {
private readonly DiscordSocketClient _client;
private readonly InteractionService _commands;
private readonly IServiceProvider _services;
public SlashHelp(IServiceProvider services) {
_commands = services.GetRequiredService<InteractionService>();
_client = services.GetRequiredService<DiscordSocketClient>();
_services = services;
// Bind menu event
_client.SelectMenuExecuted -= HandleHelpMenu; // This was to try debugging to ensure only one event was binded.
_client.SelectMenuExecuted += HandleHelpMenu;
}
[SlashCommand("help", "Get help with the bot or a command.")]
public async Task Help(
[Summary(description: "What do you need help with?")][Choice("Bot", "bot"), Choice("Command", "command")] string with = "bot"
) {
if(with == "command") {
// Build select menu for all available Slash Commands
var slashcmds = _commands.SlashCommands.ToList();
SelectMenuBuilder menu = new SelectMenuBuilder()
.WithCustomId("helpMenu")
.WithPlaceholder("Select Command...")
.WithMinValues(1).WithMaxValues(1);
foreach(var scmd in slashcmds) {
if((await scmd.CheckPreconditionsAsync(Context, _services)).IsSuccess) {
menu.AddOption(scmd.Name, scmd.Name, scmd.Description);
}
}
// Send response.
await this.RespondAsync("Select the command you would like help with:", ephemeral: true, components: new ComponentBuilder().WithSelectMenu(menu).Build());
} else {
// TODO: Implement /help with:bot
await this.RespondAsync("You need help with the bot.", ephemeral: true);
}
}
private async Task HandleHelpMenu(SocketMessageComponent menu) {
Console.WriteLine("HandleHelpMenu");
if (menu.Data.CustomId != "helpMenu") return;
await menu.UpdateAsync(m => { m.Content = $"You are requesting help for the command: **{menu.Data.Values.First()}**."; m.Components = null; });
}
}


~~


