Updated example so that it works on 0.8.1

This commit is contained in:
ViolentCrumble
2015-11-25 15:31:40 +10:00
parent 704e0c9523
commit c58d41b416

View File

@@ -1,29 +1,35 @@
class Program class Program
{ {
private static DiscordBotClient _client; private static DiscordClient _client;
static void Main(string[] args) 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(); var client = new DiscordClient();
//Log some info to console //Log some info to console
client.LogMessage += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}"); client.LogMessage += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");
//Echo any message received, provided it didn't come from us //Echo any message received, provided it didn't come from us
client.MessageCreated += async (s, e) => client.MessageReceived += async (s, e) =>
{ {
//if I am not the author
if (!e.Message.IsAuthor) if (!e.Message.IsAuthor)
await client.SendMessage(e.Message.ChannelId, e.Message.Text); //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 blocks this function until the client disconnects //Convert our sync method to an async one and blocks this function until the client disconnects
client.Run(async () => client.Run(async () =>
{ {
//Connect to the Discord server usinotng our email and password //Connect to the Discord server using our email and password
await client.Connect("discordtest@email.com", "Password123"); await client.Connect("discordtest@email.com", "Password123");
//If we are not a member of any server, use our invite code //If we are not a member of any server, use our invite code
if (!client.Servers.Any()) if (!client.AllServers.Any())
await client.AcceptInvite("aaabbbcccdddeee"); await client.AcceptInvite(client.CreateInvite("aaabbbcccdddeee"));
}); });
} }
} }