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.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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,
  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. RequestOptions options = null
  27. )
  28. {
  29. return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false);
  30. }
  31. #if FILESYSTEM
  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. RequestOptions options = null)
  40. {
  41. return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false);
  42. }
  43. #endif
  44. }
  45. }