The shell the bot maintains a connection, and then disconnects, what to do?

Hi Toster! Don't know answer me here or not, but I'll try to ask the question here for on international forums, the answer to your question I have not found.

I started working on my own arena Bot in C# using packages: Discord.Net and Newtonsoft.Json. I chose JSON as a good alternative to other permanent storage systems. Creating a preset for the bot in different textbooks, I decided to try to connect to my test server in the shell. Running the console application without debugging, the bot for some unknown reasons, tried to connect and later disconnect and so on indefinitely continued. (Library Discord.Net work for the first time)

5a9a3dfc929c2076956633.png
- - - - - - - - - - - - - - - - - - - - - - - - - -
The main script Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using the shell.WebSocket;
using the shell;

namespace DiscordPetyaBot
{
 class Program
{
 DiscordSocketClient _client;
 CommandHandler _handler;

 static void Main(string[] args)
 => new Program().StartAsync().Actual().GetResult();

 public async Task StartAsync()
{
 if (Config.bot.token == "" || Config.bot.token == null) return;
 _client = new DiscordSocketClient(new DiscordSocketConfig { LogLevel = LogSeverity.Verbose});
 _client.Log += Log;
 await _client.LoginAsync(TokenType.Bot, Config.bot.token);
 await _client.StartAsync();
 _handler = new CommandHandler();
 await _handler.InitializeAsync(_client);
 await Task.Delay(-1);
}

 private async Task Log (LogMessage msg)
{
Console.WriteLine(msg.Message);
}
}
}
CommandHandler.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using the shell.Commands;
using the shell.WebSocket;

namespace DiscordPetyaBot
{
 class CommandHandler
{
 DiscordSocketClient _client;
 CommandService _service;

 public async Task InitializeAsync(DiscordSocketClient client)
{
 _client = client;
 _service = new CommandService();
 await _service.AddModulesAsync(Assembly.GetEntryAssembly());
 _client.MessageReceived += HandleCommandAsync;
}

 private async Task HandleCommandAsync(SocketMessage s)
{
 var msg = s as SocketUserMessage;
 if (msg == null) return;
 var context = new SocketCommandContext(_client, msg);
 int argPos = 0;

 if (msg.HasStringPrefix(Config.bot.cmdPrefix, ref argPos) || msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
{
 var result = await _service.ExecuteAsync(context, argPos);
 if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
{
Console.WriteLine(result.ErrorReason);
}
}
}
}
}

What could be wrong? Use fresh versions of the libraries, a token of bot 100% correct...
Maybe I'm not the only one who faced this problem?)
Thanks In Advance!
June 7th 19 at 14:30
1 answer
June 7th 19 at 14:32
Solution
5a9aa18218d55860029384.png
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
After 6 hours, I finally was able to solve the problem yourself!
The problem was the lack of Windows 7 vendor web sites (WebSocket) used DiscordSocketClient. To solve this problem it was necessary to load the library in the solution. It is called the shell.Net.Providers.WS4Net. After that you need to change the constructor of your client:
_client = new DiscordSocketClient(new DiscordSocketConfig { WebSocketProvider = Discord.Net.Providers.WS4Net.WS4NetProvider.Instance });

Find more questions by tags C#Bots