/// <summary> /// execute as an asynchronous operation. /// </summary> /// <param name="stoppingToken">Triggered when <see cref="M:Microsoft.Extensions.Hosting.IHostedService.StopAsync(System.Threading.CancellationToken)" /> is called.</param> /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> that represents the long running operations.</returns> protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { await using var services = ConfigureServices(); DiscordSocket = services.GetRequiredService <DiscordSocketClient>(); DiscordSocket.Ready += Client_Ready; DiscordSocket.Log += Log; await DiscordSocket.LoginAsync(TokenType.Bot, (string)Config.GetValue(typeof(string), "BotToken")); await DiscordSocket.StartAsync(); await services.GetRequiredService <CommandHandler>().InstallCommandsAsync(); DiscordSocket.InteractionCreated += Client_InteractionCreated; DiscordSocket.MessageReceived += MessageReceived; await Task.Delay(-1, stoppingToken); Database.Dispose(); } }
public async Task Start() { await DiscordSocket.LoginAsync(TokenType.Bot, token); await DiscordSocket.StartAsync(); await Task.Delay(-1, cancellationToken.Token); }
/// <summary> /// Stops a Running Bot /// </summary> /// <returns></returns> public async Task Stop() { if (DiscordSocket.ConnectionState == ConnectionState.Connected) { cancellationToken.Cancel(); await DiscordSocket.LogoutAsync(); await DiscordSocket.StopAsync(); } else { throw new Exception("Bot is currently not connected. So it can't be stopped."); } }
public void Start() { Discord client = new Discord(); DiscordSocket sock = new DiscordSocket(); string token = client.Login("*****@*****.**", "Figaro123"); Console.WriteLine($"Connected: {sock.Connect()}"); Console.WriteLine($"Is Listening: {sock.SocketListener.IsListening}"); Console.WriteLine($"Is Heartbeat: {sock.SocketHeart.DoHeartbeat}"); sock.DoIdentify(token, new ConnectionProperties() { OS = "Windows", Browser = "Chrome", Device = "" }); Console.ReadLine(); sock.Send(new Payload(Opcodes.StatusUpdate, new StatusUpdate() { Status = StatusTypes.Online, AFK = false }).ToString()); Console.WriteLine(sock.Receive()); Console.ReadLine(); //Console.WriteLine(sock.Receive()); /*sock.DoIdentify("MjAzNTI2OTQ3NjAxMzgzNDI0.DnraoA.FwO0moTyQljYWI8audSVMLQTXv4", new ConnectionProperties() * { * OS = "Windows", * Browser = "App", * Device = "Desktop" * });*/ }