Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. using Discord.WebSocket;
  2. using System;
  3. using System.IO;
  4. using System.Net;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7.  
  8. namespace WindowsFormsApp
  9. {
  10. public class Program
  11. {
  12. private DiscordSocketClient _client;
  13.  
  14. private SocketChannel _channel;
  15.  
  16. public static void Main(string[] args)
  17. {
  18. new Program().MainAsync().GetAwaiter().GetResult();
  19. }
  20.  
  21. public async Task MainAsync()
  22. {
  23. using (var cancellationTokenSource = new CancellationTokenSource())
  24. {
  25. try
  26. {
  27. _client = new DiscordSocketClient();
  28. await _client.LoginAsync(Discord.TokenType.Bot,
  29. "token");
  30. await _client.StartAsync();
  31. _client.Ready += () =>
  32. {
  33. _channel = _client.GetChannel(567595590251446284);
  34. Discord.IMessageChannel channel = _channel as Discord.IMessageChannel;
  35. channel.SendMessageAsync("message");
  36. return Task.CompletedTask;
  37. };
  38. cancellationTokenSource.Cancel();
  39. var token = cancellationTokenSource.Token;
  40. if (cancellationTokenSource.IsCancellationRequested)
  41. {
  42. token.ThrowIfCancellationRequested();
  43. }
  44. await Task.Delay(-1);
  45. }
  46. catch(TaskCanceledException)
  47. {
  48.  
  49. }
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement