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

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