private async Task HandleInteraction(SocketInteraction interaction) { try { // Create an execution context that matches the generic type parameter of your InteractionModuleBase<T> modules. var context = new SocketInteractionContext(_client, interaction); // Execute the incoming command. var result = await _handler.ExecuteCommandAsync(context, _services); if (!result.IsSuccess) { switch (result.Error) { case InteractionCommandError.UnmetPrecondition: // implement break; default: break; } } } catch { // If Slash Command execution fails it is most likely that the original interaction acknowledgement will persist. It is a good idea to delete the original // response, or at least let the user know that something went wrong during the command execution. if (interaction.Type is InteractionType.ApplicationCommand) { await interaction.GetOriginalResponseAsync().ContinueWith(async(msg) => await msg.Result.DeleteAsync()); } } }
private async Task InteractionCreated(SocketInteraction interaction) { // I am not sure if bot's can trigger interactions/slash commands, but if they can we want to ignore them if (interaction.User.IsBot) { return; } var context = new SocketInteractionContext(_client, interaction); await _commands.ExecuteCommandAsync(context, _services); }
private async Task OnDiscordReady() { // SetupCommands await _interactionService.AddModulesAsync(typeof(DiscordSocketAdapter).Assembly, _provider); await _interactionService.RegisterCommandsGloballyAsync(); _client.InteractionCreated += async(x) => { var ctx = new SocketInteractionContext(_client, x); await _interactionService.ExecuteCommandAsync(ctx, _provider); }; await _mediator.Publish(new DiscordReadyNotification()); }
private async Task HandleInteraction(SocketInteraction arg) { try { // Create an execution context that matches the generic type parameter of your InteractionModuleBase<T> modules var ctx = new SocketInteractionContext(_client, arg); await _interactionService.ExecuteCommandAsync(ctx, _serviceProvider); } catch (Exception ex) { _logger.LogError(ex, "Error trying to handle interaction (e.g., from a slash command)."); // If a Slash Command execution fails it is most likely that the original interaction acknowledgement will persist. It is a good idea to delete the original // response, or at least let the user know that something went wrong during the command execution. if (arg.Type == InteractionType.ApplicationCommand) { await arg.GetOriginalResponseAsync().ContinueWith(async(msg) => await msg.Result.DeleteAsync()); } } }
private async Task HandleInteraction(SocketInteraction arg) { try { // Create an execution context that matches the generic type parameter of your InteractionModuleBase<T> modules var ctx = new SocketInteractionContext(Client, arg); await _interactionService.ExecuteCommandAsync(ctx, _provider); } catch (Exception ex) { Logger.LogError(ex, "Exception occurred whilst attempting to handle interaction."); if (arg.Type == InteractionType.ApplicationCommand) { var msg = await arg.GetOriginalResponseAsync(); await msg.DeleteAsync(); } } }
private async Task HandleInteraction(SocketInteraction arg) { try { // Create an execution context that matches the generic type parameter of your InteractionModuleBase<T> modules var ctx = new SocketInteractionContext(_client, arg); await _interactions.ExecuteCommandAsync(ctx, _serviceProvider); } catch (Exception) { Console.WriteLine($"Unable to execute {arg.Type} in channel {arg.Channel}"); // If a Slash Command execution fails it is most likely that the original interaction acknowledgement will persist. It is a good idea to delete the original // response, or at least let the user know that something went wrong during the command execution. if (arg.Type == InteractionType.ApplicationCommand) { await arg.GetOriginalResponseAsync().ContinueWith(async(msg) => await msg.Result.DeleteAsync()); } } }
private async Task OnInteractionCreatedAsync(SocketInteraction interaction) { var context = new SocketInteractionContext(_client, interaction); await _interactionService.ExecuteCommandAsync(context, _provider); }