using System; using System.Threading.Tasks; using System.IO; namespace Discord { /// An extension class for various Discord user objects. public static class UserExtensions { /// /// Sends a message via DM. /// /// The user to send the DM to. /// The message to be sent. /// Whether the message should be read aloud by Discord or not. /// The to be sent. /// The options to be used when sending the request. /// /// An awaitable Task containing the message sent to the channel. /// public static async Task SendMessageAsync(this IUser user, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) { return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); } /// /// Sends a file to this message channel with an optional caption. /// /// The user to send the DM to. /// The of the file to be sent. /// The name of the attachment. /// The message to be sent. /// Whether the message should be read aloud by Discord or not. /// The to be sent. /// The options to be used when sending the request. /// /// If you wish to upload an image and have it embedded in a embed, you may /// upload the file and refer to the file with "attachment://filename.ext" in the /// . /// /// /// An awaitable Task containing the message sent to the channel. /// public static async Task SendFileAsync(this IUser user, Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null ) { return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false); } /// /// Sends a file via DM with an optional caption. /// /// The user to send the DM to. /// The file path of the file. /// The message to be sent. /// Whether the message should be read aloud by Discord or not. /// The to be sent. /// The options to be used when sending the request. /// /// If you wish to upload an image and have it embedded in a embed, you may /// upload the file and refer to the file with "attachment://filename.ext" in the /// . /// /// /// An awaitable Task containing the message sent to the channel. /// public static async Task SendFileAsync(this IUser user, string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) { return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false); } /// /// Bans the provided user from the guild and optionally prunes their recent messages. /// /// The user to ban. /// /// The number of days to remove messages from this user for - must be between [0, 7] /// /// The reason of the ban to be written in the audit log. /// The options to be used when sending the request. /// is not between 0 to 7. public static Task BanAsync(this IGuildUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) => user.Guild.AddBanAsync(user, pruneDays, reason, options); } }