Browse Source

Refactor DiscordSocketClient init into ctor

This way we remove an IDisposableAnalyzer warning for not disposing
the client when we set the client variable.
pull/1171/head
FiniteReality 7 years ago
parent
commit
25882bba26
1 changed files with 5 additions and 2 deletions
  1. +5
    -2
      samples/01_basic_ping_bot/Program.cs

+ 5
- 2
samples/01_basic_ping_bot/Program.cs View File

@@ -16,7 +16,7 @@ namespace _01_basic_ping_bot
// - https://github.com/foxbot/patek - a more feature-filled bot, utilizing more aspects of the library // - https://github.com/foxbot/patek - a more feature-filled bot, utilizing more aspects of the library
class Program : IDisposable class Program : IDisposable
{ {
private DiscordSocketClient _client;
private readonly DiscordSocketClient _client;


// Discord.Net heavily utilizes TAP for async, so we create // Discord.Net heavily utilizes TAP for async, so we create
// an asynchronous context from the beginning. // an asynchronous context from the beginning.
@@ -26,7 +26,7 @@ namespace _01_basic_ping_bot
program.MainAsync().GetAwaiter().GetResult(); program.MainAsync().GetAwaiter().GetResult();
} }


public async Task MainAsync()
public Program()
{ {
// It is recommended to Dispose of a client when you are finished // It is recommended to Dispose of a client when you are finished
// using it, at the end of your app's lifetime. // using it, at the end of your app's lifetime.
@@ -35,7 +35,10 @@ namespace _01_basic_ping_bot
_client.Log += LogAsync; _client.Log += LogAsync;
_client.Ready += ReadyAsync; _client.Ready += ReadyAsync;
_client.MessageReceived += MessageReceivedAsync; _client.MessageReceived += MessageReceivedAsync;
}


public async Task MainAsync()
{
// Tokens should be considered secret data, and never hard-coded. // Tokens should be considered secret data, and never hard-coded.
await _client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("token")); await _client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("token"));
await _client.StartAsync(); await _client.StartAsync();


Loading…
Cancel
Save