You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

getting_started.cs 1.4 kB

1234567891011121314151617181920212223242526272829303132333435
  1. class Program
  2. {
  3. private static DiscordClient _client;
  4. static void Main(string[] args)
  5. {
  6. //This creates a new client, You can think of it as the bots own Discord window.
  7. var client = new DiscordClient();
  8. //Log some info to console
  9. client.LogMessage += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");
  10. //Echo any message received, provided it didn't come from us
  11. client.MessageReceived += async (s, e) =>
  12. {
  13. //if I am not the author
  14. if (!e.Message.IsAuthor)
  15. //Send a message back to the same channel, with the same contents.
  16. await client.SendMessage(e.Channel, e.Message.Text);
  17. };
  18. //Convert our sync method to an async one and blocks this function until the client disconnects
  19. client.Run(async () =>
  20. {
  21. //Connect to the Discord server using our email and password
  22. await client.Connect("discordtest@email.com", "Password123");
  23. //If we are not a member of any server, use our invite code
  24. if (!client.AllServers.Any())
  25. await client.AcceptInvite(client.CreateInvite("aaabbbcccdddeee"));
  26. });
  27. }
  28. }