NetCordDev / NetCord

The modern and fully customizable C# Discord library.
https://netcord.dev
MIT License
65 stars 10 forks source link

Add HasResponded for interactions #4

Closed csmir closed 1 year ago

csmir commented 1 year ago

Description

It would be welcome that instead of trying to make an API call and checking if it throws an exception, we can check inside the interaction if it has been responded to or not. For example:

try
{
  await interaction.SendResponseAsync(InteractionCallback.ChannelMessageWithSource(message));
}
catch (RestException restException) when (restException.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
  await interaction.SendFollowupMessageAsync(message);
}

could be replaced with:

if (!interaction.HasResponded)
  await interaction.SendResponseAsync(InteractionCallback.ChannelMessageWithSource(message));
else
  await interaction.SendFollowupMessageAsync(message);
csmir commented 1 year ago

Quoted from Kuba:

it's not possible to create interaction.HasResponded because everybody can use RestClient.SendInteractionResponseAsync(...)

Closing with this conclusion.