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:
committed by
Christopher F
parent
b59c48b9ec
commit
c4dcb9dc17
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user