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 KiB

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