示例#1
0
        public async Task ProcessAsync(SocketMessage rawMessage)
        {
            var prefix = _defaultPrefix;

            if (rawMessage.Channel is SocketTextChannel channel)
            {
                var guildId = channel.Guild.Id.ToString();

                var storedPrefix = await _serverManager.GetServerPrefixAsync(guildId);

                prefix = storedPrefix ?? prefix;
            }

            // Ignore system messages and messages from bots
            if (!(rawMessage is SocketUserMessage message) || message.Source != MessageSource.User)
            {
                return;
            }

            var context = new SocketCommandContext(_clientManager.Client, message);

            int argPos = 0;

            if (message.HasMentionPrefix(_clientManager.GetClientUser(), ref argPos))
            {
                await _commandManager.ExecuteAsync(context, argPos);

                return;
            }

            if (message.HasStringPrefix(prefix, ref argPos))
            {
                await _commandManager.ExecuteAsync(context, argPos);

                return;
            }
        }