From ccef6ec142bc14c058b514d9ff340f6cecd2a240 Mon Sep 17 00:00:00 2001 From: RogueException Date: Wed, 25 Nov 2015 01:46:05 -0400 Subject: [PATCH] Cleaned up getting_started.cs --- docs/samples/getting_started.cs | 53 ++++++++++++++------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/docs/samples/getting_started.cs b/docs/samples/getting_started.cs index dbb4bbe76..228ef234e 100644 --- a/docs/samples/getting_started.cs +++ b/docs/samples/getting_started.cs @@ -1,35 +1,28 @@ class Program - { - private static DiscordClient _client; +{ + static void Main(string[] args) + { + var client = new DiscordClient(); - static void Main(string[] args) - { - //This creates a new client, You can think of it as the bots own Discord window. - var client = new DiscordClient(); + //Display all log messages in the console + client.LogMessage += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}"); - //Log some info to console - client.LogMessage += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}"); + //Echo back any message received, provided it didn't come from the bot itself + client.MessageReceived += async (s, e) => + { + if (!e.Message.IsAuthor) + await client.SendMessage(e.Channel, e.Message.Text); + }; - //Echo any message received, provided it didn't come from us - client.MessageReceived += async (s, e) => - { - //if I am not the author - if (!e.Message.IsAuthor) - //Send a message back to the same channel, with the same contents. - await client.SendMessage(e.Channel, e.Message.Text); - }; + //Convert our sync method to an async one and block the Main function until the bot disconnects + client.Run(async () => + { + //Connect to the Discord server using our email and password + await client.Connect("discordtest@email.com", "Password123"); - //Convert our sync method to an async one and blocks this function until the client disconnects - client.Run(async () => - { - //Connect to the Discord server using our email and password - await client.Connect("discordtest@email.com", "Password123"); - - //If we are not a member of any server, use our invite code - if (!client.AllServers.Any()) - await client.AcceptInvite(client.CreateInvite("aaabbbcccdddeee")); - - - }); - } - } + //If we are not a member of any server, use our invite code (made beforehand in the official Discord Client) + if (!client.AllServers.Any()) + await client.AcceptInvite(client.GetInvite("aaabbbcccdddeee")); + }); + } +}