Fix UpdateAsync Remove Attachment Bug (#2766)
* Similar to PR #2742 but this now fixes the UpdateAsync attachments bug. * Update functions. * `Update` => `UpdateAsync` --------- Co-authored-by: Misha133 <mihagribkov133@gmail.com>
This commit is contained in:
@@ -141,8 +141,7 @@ namespace Discord.Rest
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="func">A delegate containing the properties to modify the message with.</param>
|
/// <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>
|
/// <param name="options">The request options for this <see langword="async"/> request.</param>
|
||||||
/// <returns>A string that contains json to write back to the incoming http request.</returns>
|
public async Task UpdateAsync(Action<MessageProperties> func, RequestOptions options = null)
|
||||||
public string Update(Action<MessageProperties> func, RequestOptions options = null)
|
|
||||||
{
|
{
|
||||||
var args = new MessageProperties();
|
var args = new MessageProperties();
|
||||||
func(args);
|
func(args);
|
||||||
@@ -200,6 +199,8 @@ namespace Discord.Rest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!args.Attachments.IsSpecified)
|
||||||
|
{
|
||||||
var response = new API.InteractionResponse
|
var response = new API.InteractionResponse
|
||||||
{
|
{
|
||||||
Type = InteractionResponseType.UpdateMessage,
|
Type = InteractionResponseType.UpdateMessage,
|
||||||
@@ -215,17 +216,36 @@ namespace Discord.Rest
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var attachments = args.Attachments.Value?.ToArray() ?? Array.Empty<FileAttachment>();
|
||||||
|
|
||||||
|
var response = new API.Rest.UploadInteractionFileParams(attachments)
|
||||||
|
{
|
||||||
|
Type = InteractionResponseType.UpdateMessage,
|
||||||
|
Content = args.Content,
|
||||||
|
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
|
||||||
|
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified,
|
||||||
|
MessageComponents = args.Components.IsSpecified
|
||||||
|
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>()
|
||||||
|
: Optional<API.ActionRowComponent[]>.Unspecified,
|
||||||
|
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional<MessageFlags>.Unspecified : Optional<MessageFlags>.Unspecified
|
||||||
|
};
|
||||||
|
|
||||||
|
await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
if (HasResponded)
|
if (HasResponded)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Cannot respond, update, or defer twice to the same interaction");
|
throw new InvalidOperationException("Cannot respond, update, or defer twice to the same interaction");
|
||||||
}
|
}
|
||||||
|
|
||||||
HasResponded = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SerializePayload(response);
|
HasResponded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -493,7 +513,7 @@ namespace Discord.Rest
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
Task IComponentInteraction.UpdateAsync(Action<MessageProperties> func, RequestOptions options)
|
Task IComponentInteraction.UpdateAsync(Action<MessageProperties> func, RequestOptions options)
|
||||||
=> Task.FromResult(Update(func, options));
|
=> UpdateAsync(func, options);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
Task IComponentInteraction.DeferLoadingAsync(bool ephemeral, RequestOptions options)
|
Task IComponentInteraction.DeferLoadingAsync(bool ephemeral, RequestOptions options)
|
||||||
|
|||||||
@@ -512,6 +512,8 @@ namespace Discord.Rest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!args.Attachments.IsSpecified)
|
||||||
|
{
|
||||||
var response = new API.InteractionResponse
|
var response = new API.InteractionResponse
|
||||||
{
|
{
|
||||||
Type = InteractionResponseType.UpdateMessage,
|
Type = InteractionResponseType.UpdateMessage,
|
||||||
@@ -527,6 +529,27 @@ namespace Discord.Rest
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var attachments = args.Attachments.Value?.ToArray() ?? Array.Empty<FileAttachment>();
|
||||||
|
|
||||||
|
var response = new API.Rest.UploadInteractionFileParams(attachments)
|
||||||
|
{
|
||||||
|
Type = InteractionResponseType.UpdateMessage,
|
||||||
|
Content = args.Content,
|
||||||
|
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
|
||||||
|
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified,
|
||||||
|
MessageComponents = args.Components.IsSpecified
|
||||||
|
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>()
|
||||||
|
: Optional<API.ActionRowComponent[]>.Unspecified,
|
||||||
|
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional<MessageFlags>.Unspecified : Optional<MessageFlags>.Unspecified
|
||||||
|
};
|
||||||
|
|
||||||
|
await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
if (HasResponded)
|
if (HasResponded)
|
||||||
@@ -535,7 +558,6 @@ namespace Discord.Rest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
|
|
||||||
HasResponded = true;
|
HasResponded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -258,6 +258,8 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!args.Attachments.IsSpecified)
|
||||||
|
{
|
||||||
var response = new API.InteractionResponse
|
var response = new API.InteractionResponse
|
||||||
{
|
{
|
||||||
Type = InteractionResponseType.UpdateMessage,
|
Type = InteractionResponseType.UpdateMessage,
|
||||||
@@ -273,6 +275,27 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var attachments = args.Attachments.Value?.ToArray() ?? Array.Empty<FileAttachment>();
|
||||||
|
|
||||||
|
var response = new API.Rest.UploadInteractionFileParams(attachments)
|
||||||
|
{
|
||||||
|
Type = InteractionResponseType.UpdateMessage,
|
||||||
|
Content = args.Content,
|
||||||
|
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
|
||||||
|
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified,
|
||||||
|
MessageComponents = args.Components.IsSpecified
|
||||||
|
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>()
|
||||||
|
: Optional<API.ActionRowComponent[]>.Unspecified,
|
||||||
|
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional<MessageFlags>.Unspecified : Optional<MessageFlags>.Unspecified
|
||||||
|
};
|
||||||
|
|
||||||
|
await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
if (HasResponded)
|
if (HasResponded)
|
||||||
@@ -281,7 +304,6 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
|
|
||||||
HasResponded = true;
|
HasResponded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user