static async Task Main() { ExampleHelper.InitLog(LogLevel.Debug); var token = ExampleHelper.GetTokenFromEnv(); ServiceCollection collection = new ServiceCollection(); collection.AddSingleton <ISerializer, ProtobufSerializer>(); collection.AddSingleton <ICacheClient, InMemoryCacheClient>(); collection.AddSingleton <IExtendedCacheClient, InMemoryCacheClient>(); collection.UseDiscord(x => { x.Token = token; }); var serviceProvider = collection.BuildServiceProvider(); var client = serviceProvider.GetService <IDiscordClient>(); client.Events.MessageCreate.Subscribe(x => { Console.WriteLine($"{x.Author.Username}: {x.Content}"); }); await client.StartAsync(default);
static async Task Main() { // Sets up Miki.Logging for internal library logging. Can be removed if you do not want to // see internal logs. ExampleHelper.InitLog(LogLevel.Information); // Fetches your token from environment values. var token = ExampleHelper.GetTokenFromEnv(); var memCache = new InMemoryCacheClient(new ProtobufSerializer()); var apiClient = new DiscordApiClient(token, memCache); // Discord direct gateway implementation. var gateway = new GatewayCluster( new GatewayProperties { ShardCount = 1, ShardId = 0, Token = token.ToString(), }); var discordClient = new DiscordClient(apiClient, gateway, memCache); // Subscribe to ready event. discordClient.Events.MessageCreate.SubscribeTask(OnMessageReceived); // Start the connection to the gateway. await gateway.StartAsync(); // Wait, else the application will close. await Task.Delay(-1); }