using DSharpPlus;
using DSharpPlus.Entities;
namespace X10D.DSharpPlus;
///
/// Extension methods for .
///
public static class DiscordMessageExtensions
{
///
/// Deletes this message after a specified delay.
///
/// The message to delete.
/// The delay before deletion.
/// The reason for the deletion.
/// is .
public static async Task DeleteAfterAsync(this DiscordMessage message, TimeSpan delay, string? reason = null)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(message);
#else
if (message is null)
{
throw new ArgumentNullException(nameof(message));
}
#endif
await Task.Delay(delay).ConfigureAwait(false);
await message.DeleteAsync(reason).ConfigureAwait(false);
}
///
/// Deletes the message as created by this task after a specified delay.
///
/// The task whose result should be deleted.
/// The delay before deletion.
/// The reason for the deletion.
/// is .
public static async Task DeleteAfterAsync(this Task task, TimeSpan delay, string? reason = null)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(task);
#else
if (task is null)
{
throw new ArgumentNullException(nameof(task));
}
#endif
DiscordMessage message = await task.ConfigureAwait(false);
await message.DeleteAfterAsync(delay, reason).ConfigureAwait(false);
}
///
/// Normalizes a so that the internal client is assured to be a specified value.
///
/// The to normalize.
/// The target client.
///
/// A whose public values will match , but whose internal client
/// is .
///
///
/// is
/// -or-
/// is
///
public static async Task NormalizeClientAsync(this DiscordMessage message, DiscordClient client)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(message);
ArgumentNullException.ThrowIfNull(client);
#else
if (message is null)
{
throw new ArgumentNullException(nameof(message));
}
if (client is null)
{
throw new ArgumentNullException(nameof(client));
}
#endif
DiscordChannel channel = await message.Channel.NormalizeClientAsync(client).ConfigureAwait(false);
return await channel.GetMessageAsync(message.Id).ConfigureAwait(false);
}
}