Example #1
0
        public async Task MainAsync()
        {
            _client      = new DiscordSocketClient();
            _client.Log += Log;

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

            await CommandAsync();

            await _client.LoginAsync(TokenType.Bot, AkiraSql.GetConfigurationValue("DiscordToken"));

            await _client.StartAsync();

            await Task.Delay(-1);
        }
Example #2
0
        public async Task HandleCommandAsync(SocketMessage msg)
        {
            SocketUserMessage    message = (SocketUserMessage)msg;
            SocketCommandContext context = new SocketCommandContext(_client, message);

            int argPos = 0;

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

            if (message.HasStringPrefix(AkiraSql.GetConfigurationValue("DiscordPrefix"), ref argPos))
            {
                var result = await _commands.ExecuteAsync(context, argPos, _services);

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