示例#1
0
        public async Task RunBotAsync()
        {
            ConfigReader.Config config = ConfigReader.LoadConfig();


            _client   = new DiscordSocketClient();
            _commands = new CommandService();

            _services = new ServiceCollection()
                        .AddSingleton(_client)
                        .AddSingleton(_commands)
                        .BuildServiceProvider();

            string token = config.token;

            _client.Log += _client_Log;

            await RegisterCommandsAsync();

            await _client.LoginAsync(TokenType.Bot, token);

            await _client.StartAsync();

            await Task.Delay(-1);
        }
示例#2
0
        private async Task HandleCommandAsync(SocketMessage arg)
        {
            ConfigReader.Config config = ConfigReader.LoadConfig();

            var message = arg as SocketUserMessage;
            var context = new SocketCommandContext(_client, message);

            if (message.Author.IsBot)
            {
                return;
            }

            int argPos = 0;

            if (message.HasStringPrefix(config.prefix, ref argPos))
            {
                var result = await _commands.ExecuteAsync(context, argPos, _services);

                if (!result.IsSuccess)
                {
                    Console.WriteLine(result.ErrorReason);
                }
            }
        }