Add missing methods to IComponentInteraction (#2201)

This commit is contained in:
d4n
2022-03-26 07:44:13 -05:00
committed by GitHub
parent 82473bce69
commit 741ed809d6
3 changed files with 30 additions and 15 deletions

View File

@@ -1,3 +1,6 @@
using System;
using System.Threading.Tasks;
namespace Discord namespace Discord
{ {
/// <summary> /// <summary>
@@ -6,7 +9,7 @@ namespace Discord
public interface IComponentInteraction : IDiscordInteraction public interface IComponentInteraction : IDiscordInteraction
{ {
/// <summary> /// <summary>
/// Gets the data received with this interaction, contains the button that was clicked. /// Gets the data received with this component interaction.
/// </summary> /// </summary>
new IComponentInteractionData Data { get; } new IComponentInteractionData Data { get; }
@@ -14,5 +17,21 @@ namespace Discord
/// Gets the message that contained the trigger for this interaction. /// Gets the message that contained the trigger for this interaction.
/// </summary> /// </summary>
IUserMessage Message { get; } IUserMessage Message { get; }
/// <summary>
/// Updates the message which this component resides in with the type <see cref="InteractionResponseType.UpdateMessage"/>
/// </summary>
/// <param name="func">A delegate containing the properties to modify the message with.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>A task that represents the asynchronous operation of updating the message.</returns>
Task UpdateAsync(Action<MessageProperties> func, RequestOptions options = null);
/// <summary>
/// Defers an interaction with the response type 5 (<see cref="InteractionResponseType.DeferredChannelMessageWithSource"/>).
/// </summary>
/// <param name="ephemeral"><see langword="true"/> to defer ephemerally, otherwise <see langword="false"/>.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>A task that represents the asynchronous operation of acknowledging the interaction.</returns>
Task DeferLoadingAsync(bool ephemeral = false, RequestOptions options = null);
} }
} }

View File

@@ -492,5 +492,13 @@ namespace Discord.Rest
/// <inheritdoc/> /// <inheritdoc/>
IUserMessage IComponentInteraction.Message => Message; IUserMessage IComponentInteraction.Message => Message;
/// <inheritdoc />
Task IComponentInteraction.UpdateAsync(Action<MessageProperties> func, RequestOptions options)
=> Task.FromResult(Update(func, options));
/// <inheritdoc />
Task IComponentInteraction.DeferLoadingAsync(bool ephemeral, RequestOptions options)
=> Task.FromResult(DeferLoading(ephemeral, options));
} }
} }

View File

@@ -202,12 +202,7 @@ namespace Discord.WebSocket
HasResponded = true; HasResponded = true;
} }
/// <summary> /// <inheritdoc/>
/// Updates the message which this component resides in with the type <see cref="InteractionResponseType.UpdateMessage"/>
/// </summary>
/// <param name="func">A delegate containing the properties to modify the message with.</param>
/// <param name="options">The request options for this <see langword="async"/> request.</param>
/// <returns>A task that represents the asynchronous operation of updating the message.</returns>
public async Task UpdateAsync(Action<MessageProperties> func, RequestOptions options = null) public async Task UpdateAsync(Action<MessageProperties> func, RequestOptions options = null)
{ {
var args = new MessageProperties(); var args = new MessageProperties();
@@ -383,14 +378,7 @@ namespace Discord.WebSocket
return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false); return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false);
} }
/// <summary> /// <inheritdoc/>
/// Defers an interaction and responds with type 5 (<see cref="InteractionResponseType.DeferredChannelMessageWithSource"/>)
/// </summary>
/// <param name="ephemeral"><see langword="true"/> to send this message ephemerally, otherwise <see langword="false"/>.</param>
/// <param name="options">The request options for this <see langword="async"/> request.</param>
/// <returns>
/// A task that represents the asynchronous operation of acknowledging the interaction.
/// </returns>
public async Task DeferLoadingAsync(bool ephemeral = false, RequestOptions options = null) public async Task DeferLoadingAsync(bool ephemeral = false, RequestOptions options = null)
{ {
if (!InteractionHelper.CanSendResponse(this)) if (!InteractionHelper.CanSendResponse(this))