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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #if FILESYSTEM
  33. /// <summary>
  34. /// Sends a file to the user via DM.
  35. /// </summary>
  36. public static async Task<IUserMessage> SendFileAsync(this IUser user,
  37. string filePath,
  38. string text = null,
  39. bool isTTS = false,
  40. Embed embed = null,
  41. RequestOptions options = null)
  42. {
  43. return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false);
  44. }
  45. #endif
  46. public static Task BanAsync(this IGuildUser user, int pruneDays = 0, string reason = null, RequestOptions options = null)
  47. => user.Guild.AddBanAsync(user, pruneDays, reason, options);
  48. }
  49. }