Update client.cs (#752)

* Update client.cs

Let's not have the client be a local variable, hm?

* Update complete.cs

* Update complete.cs

* Update client.cs and complete.cs

Let's not have the client be a local variable, hm?
This commit is contained in:
Alex Gravely
2017-07-16 11:33:01 -04:00
committed by Christopher F
parent b59c48b9ec
commit c4dcb9dc17
2 changed files with 14 additions and 11 deletions

View File

@@ -1,16 +1,17 @@
// Program.cs // Program.cs
using Discord.WebSocket; using Discord.WebSocket;
// ... // ...
private DiscordSocketClient _client;
public async Task MainAsync() public async Task MainAsync()
{ {
var client = new DiscordSocketClient(); _client = new DiscordSocketClient();
client.Log += Log; _client.Log += Log;
string token = "abcdefg..."; // Remember to keep this private! string token = "abcdefg..."; // Remember to keep this private!
await client.LoginAsync(TokenType.Bot, token); await _client.LoginAsync(TokenType.Bot, token);
await client.StartAsync(); await _client.StartAsync();
// Block this task until the program is closed. // Block this task until the program is closed.
await Task.Delay(-1); await Task.Delay(-1);
} }

View File

@@ -7,19 +7,21 @@ namespace MyBot
{ {
public class Program public class Program
{ {
private DiscordSocketClient _client;
public static void Main(string[] args) public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult(); => new Program().MainAsync().GetAwaiter().GetResult();
public async Task MainAsync() public async Task MainAsync()
{ {
var client = new DiscordSocketClient(); _client = new DiscordSocketClient();
client.Log += Log; _client.Log += Log;
client.MessageReceived += MessageReceived; _client.MessageReceived += MessageReceived;
string token = "abcdefg..."; // Remember to keep this private! string token = "abcdefg..."; // Remember to keep this private!
await client.LoginAsync(TokenType.Bot, token); await _client.LoginAsync(TokenType.Bot, token);
await client.StartAsync(); await _client.StartAsync();
// Block this task until the program is closed. // Block this task until the program is closed.
await Task.Delay(-1); await Task.Delay(-1);
@@ -39,4 +41,4 @@ namespace MyBot
return Task.CompletedTask; return Task.CompletedTask;
} }
} }
} }