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.

first-steps.cs 1.1 kB

12345678910111213141516171819202122232425262728293031323334
  1. using Discord;
  2. class Program
  3. {
  4. // Convert our sync-main to an async main method
  5. static void Main(string[] args) => new Program().Run().GetAwaiter().GetResult();
  6. // Create a DiscordClient with WebSocket support
  7. private DiscordSocketClient client;
  8. public async Task Run()
  9. {
  10. client = new DiscordSocketClient();
  11. // Place the token of your bot account here
  12. string token = "aaabbbccc";
  13. // Hook into the MessageReceived event on DiscordSocketClient
  14. client.MessageReceived += async (message) =>
  15. { // Check to see if the Message Content is "!ping"
  16. if (message.Content == "!ping")
  17. // Send 'pong' back to the channel the message was sent in
  18. await message.Channel.SendMessageAsync("pong");
  19. };
  20. // Configure the client to use a Bot token, and use our token
  21. await client.LoginAsync(TokenType.Bot, token);
  22. // Connect the client to Discord's gateway
  23. await client.ConnectAsync();
  24. // Block this task until the program is exited.
  25. await Task.Delay(-1);
  26. }
  27. }