You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserExtensions.cs 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Threading.Tasks;
  2. using System.IO;
  3. namespace Discord
  4. {
  5. public static class UserExtensions
  6. {
  7. /// <summary>
  8. /// Sends a message to the user via DM.
  9. /// </summary>
  10. public static async Task<IUserMessage> SendMessageAsync(this IUser user,
  11. string text = null,
  12. bool isTTS = false,
  13. Embed embed = null,
  14. RequestOptions options = null)
  15. {
  16. return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
  17. }
  18. /// <summary>
  19. /// Sends a file to the user via DM.
  20. /// </summary>
  21. public static async Task<IUserMessage> SendFileAsync(this IUser user,
  22. Stream stream,
  23. string filename,
  24. string text = null,
  25. bool isTTS = false,
  26. Embed embed = null,
  27. RequestOptions options = null
  28. )
  29. {
  30. return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false);
  31. }
  32. /// <summary>
  33. /// Sends a file to the user via DM.
  34. /// </summary>
  35. public static async Task<IUserMessage> SendFileAsync(this IUser user,
  36. string filePath,
  37. string text = null,
  38. bool isTTS = false,
  39. Embed embed = null,
  40. RequestOptions options = null)
  41. {
  42. return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false);
  43. }
  44. public static Task BanAsync(this IGuildUser user, int pruneDays = 0, string reason = null, RequestOptions options = null)
  45. => user.Guild.AddBanAsync(user, pruneDays, reason, options);
  46. }
  47. }