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.

events.cs 726 B

123456789101112131415161718192021222324252627
  1. class Program
  2. {
  3. private static DiscordBotClient _client;
  4. static void Main(string[] args)
  5. {
  6. var client = new DiscordClient();
  7. // Handle Events using Lambdas
  8. client.MessageCreated += (s, e) =>
  9. {
  10. if (!e.Message.IsAuthor)
  11. await client.SendMessage(e.Message.ChannelId, "foo");
  12. }
  13. // Handle Events using Event Handlers
  14. EventHandler<MessageEventArgs> handler = new EventHandler<MessageEventArgs>(HandleMessageCreated);
  15. client.MessageCreated += handler;
  16. }
  17. // NOTE: When using this method, 'client' must be accessible from outside the Main function.
  18. static void HandleMessageCreated(object sender, EventArgs e)
  19. {
  20. if (!e.Message.IsAuthor)
  21. await client.SendMessage(e.Message.ChannelId, "foo");
  22. }
  23. }