Browse Source

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?
tags/2.0.0-beta
Alex Gravely Christopher F 7 years ago
parent
commit
c4dcb9dc17
2 changed files with 14 additions and 11 deletions
  1. +6
    -5
      docs/guides/getting_started/samples/intro/client.cs
  2. +8
    -6
      docs/guides/getting_started/samples/intro/complete.cs

+ 6
- 5
docs/guides/getting_started/samples/intro/client.cs View File

@@ -1,16 +1,17 @@
// Program.cs
using Discord.WebSocket;
// ...
private DiscordSocketClient _client;
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!
await client.LoginAsync(TokenType.Bot, token);
await client.StartAsync();
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();

// Block this task until the program is closed.
await Task.Delay(-1);
}
}

+ 8
- 6
docs/guides/getting_started/samples/intro/complete.cs View File

@@ -7,19 +7,21 @@ namespace MyBot
{
public class Program
{
private DiscordSocketClient _client;
public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();

public async Task MainAsync()
{
var client = new DiscordSocketClient();
_client = new DiscordSocketClient();

client.Log += Log;
client.MessageReceived += MessageReceived;
_client.Log += Log;
_client.MessageReceived += MessageReceived;

string token = "abcdefg..."; // Remember to keep this private!
await client.LoginAsync(TokenType.Bot, token);
await client.StartAsync();
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();

// Block this task until the program is closed.
await Task.Delay(-1);
@@ -39,4 +41,4 @@ namespace MyBot
return Task.CompletedTask;
}
}
}
}

Loading…
Cancel
Save