private async Task HandleAutocomplete(SocketAutocompleteInteraction interaction) { if (interaction.User.IsBot) { return; } var user = interaction.User; switch (interaction.Channel) { case SocketDMChannel: _logger.Info("{Username:l}#{Discriminator:l} in DM's", user.Username, user.Discriminator); break; case SocketTextChannel txtChannel: _logger.Info("{Username:l}#{Discriminator:l} from {GuildName:l}/{ChannelName:l}", txtChannel.Guild.Name, txtChannel.Name); break; } var context = new ShardedInteractionContext <SocketAutocompleteInteraction>(_client, interaction); var result = await _interactionService.ExecuteCommandAsync(context, _serviceProvider); if (!result.IsSuccess) { _logger.Error(result.ErrorReason); } }
public InteractionBasedContext(ShardedInteractionContext context, Func <string, Discord.Embed, Task> responder) { Client = context.Client; Guild = context.Guild; Channel = context.Channel; User = context.User; Responder = responder; }
private async Task OnInteractionAsync(SocketInteraction interaction) { _ = Task.Run(async() => { var context = new ShardedInteractionContext(_client, interaction); await _service.ExecuteCommandAsync(context, _provider); }); await Task.CompletedTask; }
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 ShardedInteractionContext(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) { Console.WriteLine("Slash Command Executed"); try { // Create an execution context that matches the generic type parameter of your InteractionModuleBase<T> modules var ctx = new ShardedInteractionContext(_client, arg); await _interact.ExecuteCommandAsync(ctx, _services); } catch (Exception ex) { Console.WriteLine(ex); // 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()); } } }