Files
Discord.Net/src/Discord.Net.Core/Extensions/MessageExtensions.cs
Bram df8a0f7cd6 Fix: Not using the new domain name. (#1571)
* Fix: Using the correct discord domain.

* Fix: Using the correct discord domain.

* Docs: Using the correct discord domain.

* Fix: Changed canary and ptb to the new domain.
2020-09-04 17:56:05 +01:00

76 lines
3.3 KiB
C#

using System.Threading.Tasks;
namespace Discord
{
/// <summary>
/// Provides extension methods for <see cref="IMessage" />.
/// </summary>
public static class MessageExtensions
{
/// <summary>
/// Gets a URL that jumps to the message.
/// </summary>
/// <param name="msg">The message to jump to.</param>
/// <returns>
/// A string that contains a URL for jumping to the message in chat.
/// </returns>
public static string GetJumpUrl(this IMessage msg)
{
var channel = msg.Channel;
return $"https://discord.com/channels/{(channel is IDMChannel ? "@me" : $"{(channel as ITextChannel).GuildId}")}/{channel.Id}/{msg.Id}";
}
/// <summary>
/// Add multiple reactions to a message.
/// </summary>
/// <remarks>
/// This method does not bulk add reactions! It will send a request for each reaction inculded.
/// </remarks>
/// <example>
/// <code language="cs">
/// IEmote A = new Emoji("🅰");
/// IEmote B = new Emoji("🅱");
/// await msg.AddReactionsAsync(new[] { A, B });
/// </code>
/// </example>
/// <param name="msg">The message to add reactions to.</param>
/// <param name="reactions">An array of reactions to add to the message</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation for adding a reaction to this message.
/// </returns>
/// <seealso cref="IMessage.AddReactionAsync(IEmote, RequestOptions)"/>
/// <seealso cref="IEmote"/>
public static async Task AddReactionsAsync(this IUserMessage msg, IEmote[] reactions, RequestOptions options = null)
{
foreach (var rxn in reactions)
await msg.AddReactionAsync(rxn, options).ConfigureAwait(false);
}
/// <summary>
/// Remove multiple reactions from a message.
/// </summary>
/// <remarks>
/// This method does not bulk remove reactions! If you want to clear reactions from a message,
/// <see cref="IMessage.RemoveAllReactionsAsync(RequestOptions)"/>
/// </remarks>
/// <example>
/// <code language="cs">
/// await msg.RemoveReactionsAsync(currentUser, new[] { A, B });
/// </code>
/// </example>
/// <param name="msg">The message to remove reactions from.</param>
/// <param name="reactions">An array of reactions to remove from the message</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation for removing a reaction to this message.
/// </returns>
/// <seealso cref="IMessage.RemoveReactionAsync(IEmote, IUser, RequestOptions)"/>
/// <seealso cref="IEmote"/>
public static async Task RemoveReactionsAsync(this IUserMessage msg, IUser user, IEmote[] reactions, RequestOptions options = null)
{
foreach (var rxn in reactions)
await msg.RemoveReactionAsync(rxn, user, options).ConfigureAwait(false);
}
}
}