Пример #1
0
        public async void Start(string config, object[] services)
        {
            // get settings
            SettingsParser.ReloadJson(config + ".json");
            // get token
            var token = SettingsParser.GetField("token");
            // services
            ServiceCollection collection = new ServiceCollection();

            foreach (object o in services)
            {
                collection.AddSingleton(o);
            }
            Services = collection.BuildServiceProvider();
            // events
            Bot.Log             += BotOnLog;
            Bot.Ready           += BotOnReady;
            Bot.MessageReceived += BotOnMessageReceived;
            // setup
            await InstallCommands();

            // start
            await Bot.LoginAsync(TokenType.Bot, token);

            await Bot.StartAsync();

            // stop bot
            await Task.Delay(-1);
        }
Пример #2
0
        private async Task MainAsync(string[] args)
        {
            Client = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel = LogSeverity.Info
            });

            // emojis
            Emojis.Add("reverse", new Emoji("\U000025C0"));
            Emojis.Add("play", new Emoji("\U000025B6"));
            Emojis.Add("1", new Emoji("\U00000031\U000020E3"));
            Emojis.Add("2", new Emoji("\U00000032\U000020E3"));
            Emojis.Add("3", new Emoji("\U00000033\U000020E3"));
            Emojis.Add("4", new Emoji("\U00000034\U000020E3"));
            Emojis.Add("5", new Emoji("\U00000035\U000020E3"));
            Emojis.Add("6", new Emoji("\U00000036\U000020E3"));

            // settings
            SettingsParser.ReloadJson();
            var token = SettingsParser.GetField("token");

            // create services
            _services = new ServiceCollection()
                        .AddSingleton <AudioService>()
                        .AddSingleton(_audioService)
                        .BuildServiceProvider();

            // events
            Client.Ready         += Client_Ready;
            Client.Log           += Log;
            Client.ReactionAdded += Client_Reaction_Added;

            await InstallCommands();

            await Client.LoginAsync(Discord.TokenType.Bot, token);

            await Client.StartAsync();

            // dont let the bot suddenly stop
            await Task.Delay(-1);
        }