Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Discord.WebSocket;
- using System;
- using System.IO;
- using System.Net;
- using System.Threading;
- using System.Threading.Tasks;
- namespace WindowsFormsApp
- {
- public class Program
- {
- private DiscordSocketClient _client;
- private SocketChannel _channel;
- public static void Main(string[] args)
- {
- new Program().MainAsync().GetAwaiter().GetResult();
- }
- public async Task MainAsync()
- {
- using (var cancellationTokenSource = new CancellationTokenSource())
- {
- try
- {
- _client = new DiscordSocketClient();
- await _client.LoginAsync(Discord.TokenType.Bot,
- "token");
- await _client.StartAsync();
- _client.Ready += () =>
- {
- _channel = _client.GetChannel(567595590251446284);
- Discord.IMessageChannel channel = _channel as Discord.IMessageChannel;
- channel.SendMessageAsync("message");
- return Task.CompletedTask;
- };
- cancellationTokenSource.Cancel();
- var token = cancellationTokenSource.Token;
- if (cancellationTokenSource.IsCancellationRequested)
- {
- token.ThrowIfCancellationRequested();
- }
- await Task.Delay(-1);
- }
- catch(TaskCanceledException)
- {
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement