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 929 B

12345678910111213141516171819202122232425262728
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. var client = new DiscordClient();
  6. //Display all log messages in the console
  7. client.LogMessage += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");
  8. //Echo back any message received, provided it didn't come from the bot itself
  9. client.MessageReceived += async (s, e) =>
  10. {
  11. if (!e.Message.IsAuthor)
  12. await e.Channel.SendMessage(e.Message.Text);
  13. };
  14. //Convert our sync method to an async one and block the Main function until the bot disconnects
  15. client.ExecuteAndWait(async () =>
  16. {
  17. //Connect to the Discord server using our email and password
  18. await client.Connect("discordtest@email.com", "Password123");
  19. //If we are not a member of any server, use our invite code (made beforehand in the official Discord Client)
  20. if (!client.Servers.Any())
  21. await client.AcceptInvite(client.GetInvite("aaabbbcccdddeee"));
  22. });
  23. }
  24. }