public async ValueTask HandleInteractionReceived(object sender, InteractionReceivedEventArgs e) { foreach (var service in InteractionReceivedServices) { await ExecuteAsync((service, e) => service.OnInteractionReceived(e), service, e).ConfigureAwait(false); } }
public SelectionEventArgs(SelectionViewComponent selection, InteractionReceivedEventArgs e) : base(e) { Selection = selection; SelectedOptions = Interaction.SelectedValues.Select(x => Selection.Options.FirstOrDefault(y => x == y.Value)) .Where(x => x != null) // just in case Discord messes up .ToArray(); }
/// <inheritdoc/> /// <summary> /// Checks if the ID of the user who reacted is equal to <see cref="AuthorId"/>. /// </summary> protected override ValueTask <bool> CheckInteractionAsync(InteractionReceivedEventArgs e) { var authorId = AuthorId; if (authorId == null) { return(new(true)); } return(new(e.AuthorId == authorId)); }
protected override async ValueTask HandleInteractionAsync(InteractionReceivedEventArgs e) { await base.HandleInteractionAsync(e).ConfigureAwait(false); if (!IsRunning) { return; } try { await ApplyChangesAsync(e).ConfigureAwait(false); } catch (Exception ex) { Interactivity.Logger.LogError(ex, "An exception occurred while applying menu changes for view {0}.", View.GetType()); } }
protected internal abstract ValueTask ExecuteAsync(InteractionReceivedEventArgs e);
/// <inheritdoc/> /// <summary> /// Checks if the ID of the user who reacted is equal to <see cref="AuthorId"/>. /// </summary> protected override ValueTask <bool> CheckInteractionAsync(InteractionReceivedEventArgs e) => new(e.AuthorId == AuthorId);
public ButtonEventArgs(ButtonViewComponent button, InteractionReceivedEventArgs e) : base(e) { Button = button; }
public virtual async ValueTask ApplyChangesAsync(InteractionReceivedEventArgs e = null) { var view = View; if (view == null) { return; } // If we have changes, we update the message accordingly. var response = e?.Interaction.Response(); if (HasChanges || view.HasChanges) { await view.UpdateAsync().ConfigureAwait(false); var localMessage = view.ToLocalMessage(); try { if (response != null && !response.HasResponded) { // If the user hasn't responded, respond to the interaction with modifying the message. await response.ModifyMessageAsync(new LocalInteractionResponse { Content = localMessage.Content, IsTextToSpeech = localMessage.IsTextToSpeech, Embeds = localMessage.Embeds, AllowedMentions = localMessage.AllowedMentions, Components = localMessage.Components }).ConfigureAwait(false); } else if (response != null && response.HasResponded && response.ResponseType is InteractionResponseType.DeferredMessageUpdate) { // If the user deferred the response (a button is taking too long, for example), modify the message via a followup. await e.Interaction.Followup().ModifyResponseAsync(x => { x.Content = localMessage.Content; x.Embeds = new Optional <IEnumerable <LocalEmbed> >(localMessage.Embeds); x.Components = new Optional <IEnumerable <LocalRowComponent> >(localMessage.Components); x.AllowedMentions = localMessage.AllowedMentions; }).ConfigureAwait(false); } else { // If the user has responded, modify the message normally. await Message.ModifyAsync(x => { x.Content = localMessage.Content; x.Embeds = new Optional <IEnumerable <LocalEmbed> >(localMessage.Embeds); x.Components = new Optional <IEnumerable <LocalRowComponent> >(localMessage.Components); x.AllowedMentions = localMessage.AllowedMentions; }).ConfigureAwait(false); } } finally { HasChanges = false; view.HasChanges = false; } } else if (response != null && !response.HasResponded) { // Acknowledge the interaction to prevent the interaction from failing. await response.DeferAsync().ConfigureAwait(false); } }
protected internal virtual ValueTask OnInteractionReceived(InteractionReceivedEventArgs e) => default;
public ViewComponentEventArgs(InteractionReceivedEventArgs e) : base(e.Interaction, e.Member) { }