Esempio n. 1
0
        public async Task MainAsync()
        {
            SoundManager.SoundManager.SetList(SoundLoader.readList());
            // You should dispose a service provider created using ASP.NET
            // when you are finished using it, at the end of your app's lifetime.
            // If you use another dependency injection framework, you should inspect
            // its documentation for the best way to do this.
            using (var services = ConfigureServices())
            {
                var client = services.GetRequiredService <DiscordSocketClient>();

                client.Log += LogAsync;
                services.GetRequiredService <CommandService>().Log += LogAsync;
                var appSettings  = ConfigurationManager.AppSettings;
                var DiscordToken = appSettings.Get("DiscordKey");

                // Tokens should be considered secret data and never hard-coded.
                // We can read from the environment variable to avoid hardcoding.
                await client.LoginAsync(TokenType.Bot, DiscordToken);

                await client.StartAsync();

                await client.SetGameAsync("!commands | !sounds");

                // Here we initialize the logic required to register our commands.
                await services.GetRequiredService <CommandHandlingService>().InitializeAsync();

                await Task.Delay(Timeout.Infinite);
            }
        }